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

N = 1
observations = []
def solve(s):
    return {
        'first': not s['initialized'],
        'emit': s['has_value'] and s['error'] is None and (not s['initialized'] or not s['equal']),
        'initialized': False if s['reset'] else s['initialized'] or (s['has_value'] and s['error'] is None),
        'previous': s['key'] if s['has_value'] and s['error'] is None and (not s['initialized'] or not s['equal']) else s['previous'],
        'comparator_left': list(s['previous_parts']),
        'comparator_right': (['select']+(['compare'] if s['initialized'] else [])) if s['has_value'] else [],
        'payload': [dict(r) for r in s['records']],
        'credit': max(0,s['credit']-int(s['has_value'] and s['error'] is None and (not s['initialized'] or not s['equal']))),
        'compare': s['key_a'][1]==s['key_b'][1],
        'reset_emit': (s['comparison_trace'].index('exit') if 'enter' in s['comparison_trace'] and 'exit' in s['comparison_trace'] and s['comparison_trace'].index('enter')<s['comparison_trace'].index('reset')<s['comparison_trace'].index('exit') else s['comparison_trace'].index('reset')) if 'reset' in s['comparison_trace'] else None,
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'initialized': False, 'previous': 'a', 'key': 0, 'value': 'payload', 'equal': False, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 1, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, 'a'], 'key_b': [True, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': 0, 'value': 0, 'equal': True, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 3, 'seen': [], 'previous_parts': [], 'selector_appends': ['new'], 'records': [], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': ['select'], 'payload': [], 'credit': 3, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': None, 'equal': False, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 1, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [], 'comparison_trace': ['reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [], 'credit': 1, 'compare': False, 'reset_emit': 0}), ({'initialized': True, 'previous': None, 'key': None, 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': ['a'], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [True, None], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': ['a'], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': False, 'reset_emit': None}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 1, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, None], 'key_b': [True, 'b']}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': None, 'value': None, 'equal': False, 'error': 'compare', 'reset': False, 'has_value': False, 'credit': 3, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, None], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 3, 'compare': True, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 3, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 3, 'compare': False, 'reset_emit': 2})], 2: [({'initialized': False, 'previous': 'a', 'key': 'b', 'value': None, 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 6, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [True, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 6, 'compare': False, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': False, 'error': None, 'reset': True, 'has_value': True, 'credit': 6, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': True, 'initialized': False, 'previous': 'b', 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 5, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': 'b', 'value': 'payload', 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 6, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': [], 'records': [], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': ['a'], 'comparator_right': ['select'], 'payload': [], 'credit': 6, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': None, 'key': None, 'value': 'payload', 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 1, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, None], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': ['a', 'b'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': None, 'value': 0, 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 1, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [False, None], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 1, 'compare': True, 'reset_emit': 2}), ({'initialized': False, 'previous': 'a', 'key': 'b', 'value': 0, 'equal': True, 'error': 'compare', 'reset': False, 'has_value': False, 'credit': 6, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 6, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 6, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 6, 'compare': False, 'reset_emit': 2})], 3: [({'initialized': False, 'previous': 0, 'key': 'b', 'value': None, 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 9, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': ['a'], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 9, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': None, 'key': None, 'value': 'payload', 'equal': True, 'error': None, 'reset': False, 'has_value': True, 'credit': 0, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': [], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': True, 'previous': None, 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 0, 'compare': False, 'reset_emit': None}), ({'initialized': True, 'previous': 0, 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': False, 'credit': 0, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': ['a'], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': False, 'previous': 'a', 'key': 'b', 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 0, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 0, 'key': 'b', 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': True, 'credit': 9, 'seen': ['a', 'b'], 'previous_parts': [], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': [], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': False, 'emit': True, 'initialized': False, 'previous': 'b', 'comparator_left': [], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 8, 'compare': False, 'reset_emit': None}), ({'initialized': True, 'previous': None, 'key': None, 'value': 'payload', 'equal': True, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': [], 'key_a': [True, None], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 9, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 9, 'compare': False, 'reset_emit': 2})], 4: [({'initialized': False, 'previous': 'a', 'key': None, 'value': None, 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 12, 'seen': [], 'previous_parts': [], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': [], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 12, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': 0, 'value': 'payload', 'equal': False, 'error': None, 'reset': True, 'has_value': True, 'credit': 0, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': True, 'initialized': False, 'previous': 0, 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 0, 'compare': False, 'reset_emit': 0}), ({'initialized': True, 'previous': 0, 'key': 0, 'value': None, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 1, 'seen': ['a', 'b'], 'previous_parts': [], 'selector_appends': [], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': [], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': 'b', 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 12, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['reset', 'next'], 'key_a': [True, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': ['a', 'b'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 12, 'compare': False, 'reset_emit': 0}), ({'initialized': False, 'previous': 'a', 'key': 'b', 'value': None, 'equal': True, 'error': 'compare', 'reset': True, 'has_value': False, 'credit': 1, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['reset', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 0}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': None, 'equal': True, 'error': None, 'reset': False, 'has_value': True, 'credit': 12, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [False, None], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 12, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 12, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 12, 'compare': False, 'reset_emit': 2})], 5: [({'initialized': False, 'previous': 'a', 'key': None, 'value': 'payload', 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 15, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 15, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 0, 'key': 'b', 'value': None, 'equal': True, 'error': None, 'reset': True, 'has_value': True, 'credit': 1, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [False, None], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': None, 'value': 0, 'equal': True, 'error': None, 'reset': False, 'has_value': False, 'credit': 1, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': [], 'payload': [], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 0, 'key': None, 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 15, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 15, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': None, 'key': None, 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': True, 'credit': 0, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, None], 'key_b': [True, 'b']}, {'first': False, 'emit': True, 'initialized': False, 'previous': None, 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 0, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': 0, 'value': 'payload', 'equal': False, 'error': 'compare', 'reset': False, 'has_value': False, 'credit': 15, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': [], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['reset', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 15, 'compare': False, 'reset_emit': 0}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 15, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 15, 'compare': False, 'reset_emit': 2})]}
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 {
        'first': not s['initialized'],
        'emit': s['has_value'] and s['error'] is None and (not s['initialized'] or not s['equal']),
        'initialized': False if s['reset'] else s['initialized'] or (s['has_value'] and s['error'] is None),
        'previous': s['key'] if s['has_value'] and s['error'] is None and (not s['initialized'] or not s['equal']) else s['previous'],
        'comparator_left': list(s['previous_parts']),
        'comparator_right': (['select']+(['compare'] if s['initialized'] else [])) if s['has_value'] else [],
        'payload': [dict(r) for r in s['records']],
        'credit': max(0,s['credit']-int(s['has_value'] and s['error'] is None and (not s['initialized'] or not s['equal']))),
        'compare': s['key_a'][0]==s['key_b'][0],
        'reset_emit': (s['comparison_trace'].index('exit') if 'enter' in s['comparison_trace'] and 'exit' in s['comparison_trace'] and s['comparison_trace'].index('enter')<s['comparison_trace'].index('reset')<s['comparison_trace'].index('exit') else s['comparison_trace'].index('reset')) if 'reset' in s['comparison_trace'] else None,
    }
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = {1: [({'initialized': False, 'previous': 'a', 'key': 0, 'value': 'payload', 'equal': False, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 1, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, 'a'], 'key_b': [True, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': 0, 'value': 0, 'equal': True, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 3, 'seen': [], 'previous_parts': [], 'selector_appends': ['new'], 'records': [], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': ['select'], 'payload': [], 'credit': 3, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': None, 'equal': False, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 1, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [], 'comparison_trace': ['reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [], 'credit': 1, 'compare': False, 'reset_emit': 0}), ({'initialized': True, 'previous': None, 'key': None, 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': ['a'], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [True, None], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': ['a'], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': False, 'reset_emit': None}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 1, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, None], 'key_b': [True, 'b']}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': None, 'value': None, 'equal': False, 'error': 'compare', 'reset': False, 'has_value': False, 'credit': 3, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, None], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 3, 'compare': True, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 3, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 3, 'compare': False, 'reset_emit': 2})], 2: [({'initialized': False, 'previous': 'a', 'key': 'b', 'value': None, 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 6, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [True, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 6, 'compare': False, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': False, 'error': None, 'reset': True, 'has_value': True, 'credit': 6, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': True, 'initialized': False, 'previous': 'b', 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 5, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': 'b', 'value': 'payload', 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 6, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': [], 'records': [], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': ['a'], 'comparator_right': ['select'], 'payload': [], 'credit': 6, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': None, 'key': None, 'value': 'payload', 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 1, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, None], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': ['a', 'b'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': None, 'value': 0, 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 1, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [False, None], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 1, 'compare': True, 'reset_emit': 2}), ({'initialized': False, 'previous': 'a', 'key': 'b', 'value': 0, 'equal': True, 'error': 'compare', 'reset': False, 'has_value': False, 'credit': 6, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 6, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 6, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 6, 'compare': False, 'reset_emit': 2})], 3: [({'initialized': False, 'previous': 0, 'key': 'b', 'value': None, 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 9, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': ['a'], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 9, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': None, 'key': None, 'value': 'payload', 'equal': True, 'error': None, 'reset': False, 'has_value': True, 'credit': 0, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': [], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': True, 'previous': None, 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 0, 'compare': False, 'reset_emit': None}), ({'initialized': True, 'previous': 0, 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': False, 'credit': 0, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': ['a'], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': False, 'previous': 'a', 'key': 'b', 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 0, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 0, 'key': 'b', 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': True, 'credit': 9, 'seen': ['a', 'b'], 'previous_parts': [], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': [], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': False, 'emit': True, 'initialized': False, 'previous': 'b', 'comparator_left': [], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 8, 'compare': False, 'reset_emit': None}), ({'initialized': True, 'previous': None, 'key': None, 'value': 'payload', 'equal': True, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': [], 'key_a': [True, None], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 9, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 9, 'compare': False, 'reset_emit': 2})], 4: [({'initialized': False, 'previous': 'a', 'key': None, 'value': None, 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 12, 'seen': [], 'previous_parts': [], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': [], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 12, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': 0, 'value': 'payload', 'equal': False, 'error': None, 'reset': True, 'has_value': True, 'credit': 0, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': True, 'initialized': False, 'previous': 0, 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 0, 'compare': False, 'reset_emit': 0}), ({'initialized': True, 'previous': 0, 'key': 0, 'value': None, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 1, 'seen': ['a', 'b'], 'previous_parts': [], 'selector_appends': [], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': [], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': 'b', 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': False, 'credit': 12, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['reset', 'next'], 'key_a': [True, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': ['a', 'b'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 12, 'compare': False, 'reset_emit': 0}), ({'initialized': False, 'previous': 'a', 'key': 'b', 'value': None, 'equal': True, 'error': 'compare', 'reset': True, 'has_value': False, 'credit': 1, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['reset', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 0}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': None, 'equal': True, 'error': None, 'reset': False, 'has_value': True, 'credit': 12, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [False, None], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 12, 'compare': False, 'reset_emit': 2}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 12, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 12, 'compare': False, 'reset_emit': 2})], 5: [({'initialized': False, 'previous': 'a', 'key': None, 'value': 'payload', 'equal': False, 'error': 'compare', 'reset': False, 'has_value': True, 'credit': 15, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': True, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 15, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 0, 'key': 'b', 'value': None, 'equal': True, 'error': None, 'reset': True, 'has_value': True, 'credit': 1, 'seen': [], 'previous_parts': ['a'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [False, None], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': None, 'value': 0, 'equal': True, 'error': None, 'reset': False, 'has_value': False, 'credit': 1, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': [], 'payload': [], 'credit': 1, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 0, 'key': None, 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 15, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 0, 'comparator_left': ['a'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 15, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': None, 'key': None, 'value': 0, 'equal': False, 'error': None, 'reset': True, 'has_value': True, 'credit': 0, 'seen': [], 'previous_parts': ['a', 'b'], 'selector_appends': ['a'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'reset', 'exit', 'next'], 'key_a': [True, None], 'key_b': [True, 'b']}, {'first': False, 'emit': True, 'initialized': False, 'previous': None, 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 0, 'compare': False, 'reset_emit': 2}), ({'initialized': True, 'previous': 'a', 'key': 0, 'value': 'payload', 'equal': False, 'error': 'compare', 'reset': False, 'has_value': False, 'credit': 15, 'seen': ['a', 'b'], 'previous_parts': ['a'], 'selector_appends': [], 'records': [{'key': 'a', 'detail': 0}], 'comparison_trace': ['reset', 'next'], 'key_a': [True, 'a'], 'key_b': [False, None]}, {'first': False, 'emit': False, 'initialized': True, 'previous': 'a', 'comparator_left': ['a'], 'comparator_right': [], 'payload': [{'key': 'a', 'detail': 0}], 'credit': 15, 'compare': False, 'reset_emit': 0}), ({'initialized': False, 'previous': None, 'key': None, 'value': None, 'equal': False, 'error': None, 'reset': False, 'has_value': False, 'credit': 0, 'seen': [], 'previous_parts': [], 'selector_appends': [], 'records': [], 'comparison_trace': [], 'key_a': [False, None], 'key_b': [False, None]}, {'first': True, 'emit': False, 'initialized': False, 'previous': None, 'comparator_left': [], 'comparator_right': [], 'payload': [], 'credit': 0, 'compare': True, 'reset_emit': None}), ({'initialized': True, 'previous': 'a', 'key': 'b', 'value': 'payload', 'equal': True, 'error': 'compare', 'reset': True, 'has_value': True, 'credit': 15, 'seen': ['a', 'b'], 'previous_parts': ['a', 'b'], 'selector_appends': ['new'], 'records': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'comparison_trace': ['enter', 'exit', 'reset', 'next'], 'key_a': [True, 'a'], 'key_b': [True, 'b']}, {'first': False, 'emit': False, 'initialized': False, 'previous': 'a', 'comparator_left': ['a', 'b'], 'comparator_right': ['select', 'compare'], 'payload': [{'key': 'a', 'detail': 0}, {'key': 'b', 'detail': 'kept'}], 'credit': 15, 'compare': False, 'reset_emit': 2})]}
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:
Default distinct equality conflates an absent selected key with explicit None; the returned lifecycle plan violates the stated transition contract.

Plan a consecutive-distinct observer stage with explicit initialized bit. None and zero are valid keys. Comparison uses the incoming key and previous accepted key. A reset clears initialization but does not emit data. Comparator failure terminates the stage without replacing the prior key. Nonconsecutive repeats remain eligible. Suppressed values do not consume downstream credit. A prior composite key is snapshotted before the selector appends parts to its live storage; comparator-left receives the pre-selector list exactly. Selector/comparator call trace is select, then compare only when a previous key is initialized; absent input makes no calls. Key extraction may read a record but output records preserve every original field, including metadata on later records. A reset requested inside one active equality comparison is applied at comparator exit; outside a comparison it applies at its own trace position. Optional selected keys are [present,value]; equality compares presence first and compares values only for two present keys. 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: first = not s['initialized']; emit = s['has_value'] and s['error'] is None and (not s['initialized'] or not s['equal']); initialized = False if s['reset'] else s['initialized'] or (s['has_value'] and s['error'] is None); previous = s['key'] if s['has_value'] and s['error'] is None and (not s['initialized'] or not s['equal']) else s['previous']; comparator_left = list(s['previous_parts']); comparator_right = (['select']+(['compare'] if s['initialized'] else [])) if s['has_value'] else []; payload = [dict(r) for r in s['records']]; credit = max(0,s['credit']-int(s['has_value'] and s['error'] is None and (not s['initialized'] or not s['equal']))); compare = s['key_a'][0]==s['key_b'][0] and (not s['key_a'][0] or s['key_a'][1]==s['key_b'][1]); reset_emit = (s['comparison_trace'].index('exit') if 'enter' in s['comparison_trace'] and 'exit' in s['comparison_trace'] and s['comparison_trace'].index('enter')<s['comparison_trace'].index('reset')<s['comparison_trace'].index('exit') else s['comparison_trace'].index('reset')) if 'reset' in s['comparison_trace'] else None

split: open-access