FAILURE MAP
← Case archive

FA-97246 / Recipe scaling and nutrition / Open access

Sub-recipe allergen roll-up: contains precedence · case 01

Milk appears both as contains and as may contain.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Precautionary allergens already declared as contained are not removed.

VERIFIED REPAIR

Subtract all contained allergens from may-contain.

Unsuccessful approach: Subtracting only the root recipe's allergens keeps duplicates from sub-recipes.

Case contract

recipes maps name -> {allergens, may_contain, uses}. Walk root and every used sub-recipe (depth first, in order). Names canonicalize: trim, lower, synonyms dairy->milk, peanuts->peanut, tree nuts->tree nut, eggs->egg. Result {contains, may_contain (minus contains), error: None}, both sorted. A shared sub-recipe reached twice (diamond) is fine; a cycle returns error "cycle: name" and an unknown name "unknown: name", with empty lists, stopping at the first error.

Why this case matters

Menu allergen matrices must propagate through nested sub-recipes without false cycle errors.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(recipes, root):
    SYN = {'dairy': 'milk', 'peanuts': 'peanut', 'tree nuts': 'tree nut', 'eggs': 'egg'}
    def canon(a):
        a = a.strip().lower()
        return SYN.get(a, a)
    contains, may = set(), set()
    state = {}
    def visit(n):
        if n not in recipes:
            return 'unknown: ' + n
        if state.get(n) == 1:
            return 'cycle: ' + n
        if state.get(n) == 2:
            return None
        state[n] = 1
        r = recipes[n]
        contains.update(canon(a) for a in r.get('allergens', []))
        may.update(canon(a) for a in r.get('may_contain', []))
        for s in r.get('uses', []):
            e = visit(s)
            if e:
                return e
        state[n] = 2
        return None
    err = visit(root)
    if err:
        return {'contains': [], 'may_contain': [], 'error': err}
    return {'contains': sorted(contains), 'may_contain': sorted(may), 'error': None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': ['soy'], 'may_contain': ['dairy', 'Egg'], 'uses': ['topping']},
     'crust': {'allergens': ['tree nuts', 'dairy'], 'may_contain': ['wheat'], 'uses': []},
     'filling': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': []},
     'sauce': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': ['filling', 'base']},
     'topping': {'allergens': ['peanuts', 'milk'], 'may_contain': ['wheat', 'milk'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'peanut', 'soy'], 'error': None, 'may_contain': ['egg', 'wheat']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [],
              'may_contain': ['dairy', ' sesame '],
              'uses': ['sauce', 'crust', 'filling', 'topping']},
     'crust': {'allergens': ['tree nuts'], 'may_contain': ['soy', 'Egg'], 'uses': []},
     'filling': {'allergens': ['wheat', 'peanuts'], 'may_contain': [], 'uses': []},
     'sauce': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['wheat', 'Egg'], 'may_contain': ['Egg'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'milk', 'peanut', 'tree nut', 'wheat'],
    'error': None,
    'may_contain': ['sesame', 'soy']}],
  ['generated control 1',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'crust': {'allergens': ['wheat'], 'may_contain': ['wheat'], 'uses': []},
     'filling': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': ['milk'], 'may_contain': ['peanuts'], 'uses': ['crust']},
     'topping': {'allergens': [], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': [], 'error': None, 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['filling']},
     'crust': {'allergens': ['soy'], 'may_contain': ['soy'], 'uses': ['topping']},
     'filling': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': ['soy', 'dairy'], 'may_contain': ['Egg'], 'uses': ['crust', 'filling']},
     'topping': {'allergens': ['soy', 'dairy'], 'may_contain': ['eggs'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['egg']}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': ['milk', ' sesame '], 'uses': []},
     'crust': {'allergens': ['wheat', 'tree nuts'], 'may_contain': ['milk'], 'uses': ['filling']},
     'filling': {'allergens': ['tree nuts', 'soy'], 'may_contain': [' sesame ', 'wheat'], 'uses': ['sauce']},
     'sauce': {'allergens': ['wheat', 'tree nuts'], 'may_contain': ['Egg'], 'uses': ['crust', 'filling']},
     'topping': {'allergens': ['dairy'], 'may_contain': ['dairy', 'eggs'], 'uses': []}},
    'base'],
   {'contains': [], 'error': None, 'may_contain': ['milk', 'sesame']}]],
 [['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['unknown sub', [{'base': {'uses': ['ghost']}}, 'base'],
   {'contains': [], 'error': 'unknown: ghost', 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': ['wheat'],
              'may_contain': ['milk'],
              'uses': ['sauce', 'crust', 'filling', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['dairy', 'Egg'], 'uses': ['filling']},
     'filling': {'allergens': ['eggs', 'peanuts'], 'may_contain': ['tree nuts', 'milk'], 'uses': []},
     'sauce': {'allergens': ['peanuts', 'wheat'],
               'may_contain': ['milk', 'wheat'],
               'uses': ['crust', 'topping']},
     'topping': {'allergens': ['eggs', ' sesame '], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'peanut', 'sesame', 'wheat'], 'error': None, 'may_contain': ['milk', 'tree nut']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': ['soy'], 'may_contain': ['dairy', 'milk'], 'uses': ['filling', 'topping']},
     'crust': {'allergens': ['wheat', 'peanuts'], 'may_contain': [' sesame '], 'uses': []},
     'filling': {'allergens': [' sesame '], 'may_contain': ['soy'], 'uses': ['topping']},
     'sauce': {'allergens': ['peanuts', 'Egg'],
               'may_contain': ['wheat', 'Egg'],
               'uses': ['crust', 'topping']},
     'topping': {'allergens': ['Egg', 'wheat'], 'may_contain': ['eggs', ' sesame '], 'uses': []}},
    'base'],
   {'contains': ['egg', 'sesame', 'soy', 'wheat'], 'error': None, 'may_contain': ['milk']}],
  ['generated control 1',
   [{'base': {'allergens': ['tree nuts', 'dairy'],
              'may_contain': ['soy', ' sesame '],
              'uses': ['sauce', 'topping', 'mystery']},
     'crust': {'allergens': ['soy'], 'may_contain': [], 'uses': ['topping', 'mystery']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': ['milk'], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['milk', 'tree nuts'], 'uses': ['topping']},
     'topping': {'allergens': [], 'may_contain': ['dairy', 'milk'], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'unknown: mystery', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': [], 'may_contain': ['eggs'], 'uses': ['sauce', 'topping']},
     'crust': {'allergens': ['wheat'], 'may_contain': ['dairy'], 'uses': ['filling', 'topping', 'sauce']},
     'filling': {'allergens': [], 'may_contain': [' sesame ', 'eggs'], 'uses': []},
     'sauce': {'allergens': ['wheat', 'dairy'], 'may_contain': ['soy', 'wheat'], 'uses': ['filling', 'base']},
     'topping': {'allergens': [], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': []},
     'crust': {'allergens': ['dairy', 'peanuts'], 'may_contain': [], 'uses': ['filling', 'topping']},
     'filling': {'allergens': ['Egg'], 'may_contain': ['peanuts', 'dairy'], 'uses': ['topping']},
     'sauce': {'allergens': ['milk'], 'may_contain': ['soy', 'Egg'], 'uses': ['filling']},
     'topping': {'allergens': ['tree nuts', 'milk'], 'may_contain': ['soy', 'tree nuts'], 'uses': []}},
    'base'],
   {'contains': [], 'error': None, 'may_contain': ['tree nut']}]],
 [['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['unknown sub', [{'base': {'uses': ['ghost']}}, 'base'],
   {'contains': [], 'error': 'unknown: ghost', 'may_contain': []}],
  ['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['regression: contains precedence',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['sauce', 'crust', 'topping']},
     'crust': {'allergens': ['dairy', 'tree nuts'], 'may_contain': ['wheat'], 'uses': ['filling']},
     'filling': {'allergens': ['peanuts', 'wheat'], 'may_contain': ['Egg'], 'uses': []},
     'sauce': {'allergens': ['milk', 'soy'], 'may_contain': [], 'uses': ['crust']},
     'topping': {'allergens': [], 'may_contain': ['wheat', ' sesame '], 'uses': []}},
    'base'],
   {'contains': ['milk', 'peanut', 'soy', 'tree nut', 'wheat'],
    'error': None,
    'may_contain': ['egg', 'sesame']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [], 'may_contain': ['soy', 'eggs'], 'uses': ['sauce']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['filling']},
     'filling': {'allergens': ['Egg', 'milk'], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['peanuts'], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['dairy'], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': ['egg', 'milk'], 'error': None, 'may_contain': ['peanut', 'soy']}],
  ['generated control 1',
   [{'base': {'allergens': [' sesame ', 'eggs'], 'may_contain': [], 'uses': ['sauce', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['milk'], 'uses': ['topping', 'sauce']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': ['dairy', 'peanuts'], 'uses': []},
     'sauce': {'allergens': [], 'may_contain': [' sesame '], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['soy'], 'may_contain': ['tree nuts'], 'uses': ['base']}},
    'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': ['eggs', 'wheat'], 'may_contain': ['tree nuts'], 'uses': []},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'filling': {'allergens': [], 'may_contain': ['eggs'], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['dairy'], 'uses': ['filling', 'topping']},
     'topping': {'allergens': [], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'wheat'], 'error': None, 'may_contain': ['tree nut']}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': ['peanuts'], 'uses': ['sauce', 'crust']},
     'crust': {'allergens': ['tree nuts'], 'may_contain': [' sesame '], 'uses': ['topping']},
     'filling': {'allergens': [], 'may_contain': ['wheat'], 'uses': []},
     'sauce': {'allergens': ['dairy'], 'may_contain': [' sesame '], 'uses': ['crust', 'filling', 'topping']},
     'topping': {'allergens': [], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'tree nut'], 'error': None, 'may_contain': ['peanut', 'sesame', 'wheat']}]],
 [['unknown sub', [{'base': {'uses': ['ghost']}}, 'base'],
   {'contains': [], 'error': 'unknown: ghost', 'may_contain': []}],
  ['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': ['dairy'],
              'may_contain': [' sesame ', 'tree nuts'],
              'uses': ['sauce', 'filling', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': ['topping']},
     'filling': {'allergens': ['dairy', 'soy'], 'may_contain': [], 'uses': []},
     'sauce': {'allergens': ['milk'], 'may_contain': ['dairy', 'wheat'], 'uses': []},
     'topping': {'allergens': ['soy'], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['sesame', 'tree nut', 'wheat']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [' sesame '], 'may_contain': ['wheat', 'eggs'], 'uses': ['crust']},
     'crust': {'allergens': ['peanuts', 'Egg'], 'may_contain': ['wheat'], 'uses': []},
     'filling': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['wheat'], 'uses': ['filling', 'topping']},
     'topping': {'allergens': [], 'may_contain': ['soy', 'tree nuts'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'peanut', 'sesame'], 'error': None, 'may_contain': ['wheat']}],
  ['generated control 1',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['crust', 'topping', 'mystery']},
     'crust': {'allergens': [], 'may_contain': ['milk', 'eggs'], 'uses': ['filling', 'topping']},
     'filling': {'allergens': ['eggs', 'milk'], 'may_contain': ['dairy'], 'uses': []},
     'sauce': {'allergens': ['eggs'], 'may_contain': ['Egg'], 'uses': ['filling']},
     'topping': {'allergens': [], 'may_contain': ['Egg'], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'unknown: mystery', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': [], 'may_contain': [' sesame '], 'uses': ['sauce', 'crust']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': [], 'uses': ['topping', 'base']},
     'sauce': {'allergens': ['Egg', 'wheat'], 'may_contain': [' sesame '], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['tree nuts'], 'may_contain': ['peanuts'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'tree nut', 'wheat'], 'error': None, 'may_contain': ['peanut', 'sesame']}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['crust', 'filling']},
     'crust': {'allergens': [], 'may_contain': ['milk'], 'uses': ['filling', 'topping']},
     'filling': {'allergens': ['eggs', 'Egg'], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['crust', 'filling', 'topping', 'base']},
     'topping': {'allergens': ['peanuts'], 'may_contain': [], 'uses': ['crust']}},
    'base'],
   {'contains': [], 'error': 'cycle: crust', 'may_contain': []}]],
 [['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': [], 'may_contain': ['wheat', 'dairy'], 'uses': ['sauce', 'crust', 'filling']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': []},
     'filling': {'allergens': ['Egg', 'eggs'], 'may_contain': [' sesame '], 'uses': []},
     'sauce': {'allergens': ['dairy', 'tree nuts'], 'may_contain': ['dairy', ' sesame '], 'uses': []},
     'topping': {'allergens': ['Egg', 'peanuts'], 'may_contain': ['milk'], 'uses': ['base']}},
    'base'],
   {'contains': ['egg', 'milk', 'tree nut'], 'error': None, 'may_contain': ['sesame', 'wheat']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [], 'may_contain': ['soy'], 'uses': ['sauce', 'filling']},
     'crust': {'allergens': ['milk'], 'may_contain': [' sesame '], 'uses': ['topping']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': [], 'uses': []},
     'sauce': {'allergens': ['milk'],
               'may_contain': ['wheat', 'eggs'],
               'uses': ['crust', 'filling', 'topping']},
     'topping': {'allergens': ['soy'], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': ['milk', 'soy', 'tree nut'], 'error': None, 'may_contain': ['egg', 'sesame', 'wheat']}],
  ['generated control 1',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['sauce', 'crust']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['filling', 'base']},
     'filling': {'allergens': ['dairy'], 'may_contain': ['wheat'], 'uses': []},
     'sauce': {'allergens': ['eggs'],
               'may_contain': ['tree nuts', 'Egg'],
               'uses': ['filling', 'topping', 'base']},
     'topping': {'allergens': ['milk'], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': ['Egg'], 'may_contain': ['eggs'], 'uses': ['sauce', 'crust', 'mystery']},
     'crust': {'allergens': ['dairy'], 'may_contain': ['Egg'], 'uses': ['topping']},
     'filling': {'allergens': ['Egg', 'tree nuts'], 'may_contain': [' sesame ', 'soy'], 'uses': []},
     'sauce': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['crust', 'base']},
     'topping': {'allergens': ['tree nuts'], 'may_contain': [], 'uses': ['crust']}},
    'base'],
   {'contains': [], 'error': 'cycle: crust', 'may_contain': []}],
  ['generated control 3',
   [{'base': {'allergens': ['wheat', 'peanuts'],
              'may_contain': [' sesame ', 'peanuts'],
              'uses': ['crust', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['Egg'], 'uses': ['filling']},
     'filling': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['dairy', 'peanuts'], 'uses': ['crust']},
     'topping': {'allergens': ['wheat', 'peanuts'], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': ['peanut', 'wheat'], 'error': None, 'may_contain': ['egg', 'sesame']}]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
flat recipe{'contains': ['milk'], 'error': None, 'may_contain': ['soy']}{'contains': ['milk'], 'error': None, 'may_contain': ['soy']}Passed
diamond sharing{'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}{'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}Passed
cycle{'contains': [], 'error': 'cycle: base', 'may_contain': []}{'contains': [], 'error': 'cycle: base', 'may_contain': []}Passed
regression: contains precedence{'contains': ['milk', 'peanut', 'soy'], 'error': None, 'may_contain': ['egg', 'milk', 'wheat']}{'contains': ['milk', 'peanut', 'soy'], 'error': None, 'may_contain': ['egg', 'wheat']}Failed
repair check: contains precedence{'contains': ['egg', 'milk', 'peanut', 'tree nut', 'wheat'], 'error': None, 'may_contain': ['egg', 'milk', 'sesame', 'soy']}{'contains': ['egg', 'milk', 'peanut', 'tree nut', 'wheat'], 'error': None, 'may_contain': ['sesame', 'soy']}Failed
generated control 1{'contains': [], 'error': None, 'may_contain': []}{'contains': [], 'error': None, 'may_contain': []}Passed
generated control 2{'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['egg']}{'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['egg']}Passed
generated control 3{'contains': [], 'error': None, 'may_contain': ['milk', 'sesame']}{'contains': [], 'error': None, 'may_contain': ['milk', 'sesame']}Passed

SHA-256 / 5038d507eea94d02ab4c2d4e723e089f672e1dfe8c61d8cd79f55ad5c195a3c8

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(recipes, root):
    SYN = {'dairy': 'milk', 'peanuts': 'peanut', 'tree nuts': 'tree nut', 'eggs': 'egg'}
    def canon(a):
        a = a.strip().lower()
        return SYN.get(a, a)
    contains, may = set(), set()
    state = {}
    def visit(n):
        if n not in recipes:
            return 'unknown: ' + n
        if state.get(n) == 1:
            return 'cycle: ' + n
        if state.get(n) == 2:
            return None
        state[n] = 1
        r = recipes[n]
        contains.update(canon(a) for a in r.get('allergens', []))
        may.update(canon(a) for a in r.get('may_contain', []))
        for s in r.get('uses', []):
            e = visit(s)
            if e:
                return e
        state[n] = 2
        return None
    err = visit(root)
    if err:
        return {'contains': [], 'may_contain': [], 'error': err}
    return {'contains': sorted(contains), 'may_contain': sorted(may - {canon(a) for a in recipes[root].get('allergens', [])}), 'error': None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': ['soy'], 'may_contain': ['dairy', 'Egg'], 'uses': ['topping']},
     'crust': {'allergens': ['tree nuts', 'dairy'], 'may_contain': ['wheat'], 'uses': []},
     'filling': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': []},
     'sauce': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': ['filling', 'base']},
     'topping': {'allergens': ['peanuts', 'milk'], 'may_contain': ['wheat', 'milk'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'peanut', 'soy'], 'error': None, 'may_contain': ['egg', 'wheat']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [],
              'may_contain': ['dairy', ' sesame '],
              'uses': ['sauce', 'crust', 'filling', 'topping']},
     'crust': {'allergens': ['tree nuts'], 'may_contain': ['soy', 'Egg'], 'uses': []},
     'filling': {'allergens': ['wheat', 'peanuts'], 'may_contain': [], 'uses': []},
     'sauce': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['wheat', 'Egg'], 'may_contain': ['Egg'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'milk', 'peanut', 'tree nut', 'wheat'],
    'error': None,
    'may_contain': ['sesame', 'soy']}],
  ['generated control 1',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'crust': {'allergens': ['wheat'], 'may_contain': ['wheat'], 'uses': []},
     'filling': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': ['milk'], 'may_contain': ['peanuts'], 'uses': ['crust']},
     'topping': {'allergens': [], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': [], 'error': None, 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['filling']},
     'crust': {'allergens': ['soy'], 'may_contain': ['soy'], 'uses': ['topping']},
     'filling': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': ['soy', 'dairy'], 'may_contain': ['Egg'], 'uses': ['crust', 'filling']},
     'topping': {'allergens': ['soy', 'dairy'], 'may_contain': ['eggs'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['egg']}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': ['milk', ' sesame '], 'uses': []},
     'crust': {'allergens': ['wheat', 'tree nuts'], 'may_contain': ['milk'], 'uses': ['filling']},
     'filling': {'allergens': ['tree nuts', 'soy'], 'may_contain': [' sesame ', 'wheat'], 'uses': ['sauce']},
     'sauce': {'allergens': ['wheat', 'tree nuts'], 'may_contain': ['Egg'], 'uses': ['crust', 'filling']},
     'topping': {'allergens': ['dairy'], 'may_contain': ['dairy', 'eggs'], 'uses': []}},
    'base'],
   {'contains': [], 'error': None, 'may_contain': ['milk', 'sesame']}]],
 [['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['unknown sub', [{'base': {'uses': ['ghost']}}, 'base'],
   {'contains': [], 'error': 'unknown: ghost', 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': ['wheat'],
              'may_contain': ['milk'],
              'uses': ['sauce', 'crust', 'filling', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['dairy', 'Egg'], 'uses': ['filling']},
     'filling': {'allergens': ['eggs', 'peanuts'], 'may_contain': ['tree nuts', 'milk'], 'uses': []},
     'sauce': {'allergens': ['peanuts', 'wheat'],
               'may_contain': ['milk', 'wheat'],
               'uses': ['crust', 'topping']},
     'topping': {'allergens': ['eggs', ' sesame '], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'peanut', 'sesame', 'wheat'], 'error': None, 'may_contain': ['milk', 'tree nut']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': ['soy'], 'may_contain': ['dairy', 'milk'], 'uses': ['filling', 'topping']},
     'crust': {'allergens': ['wheat', 'peanuts'], 'may_contain': [' sesame '], 'uses': []},
     'filling': {'allergens': [' sesame '], 'may_contain': ['soy'], 'uses': ['topping']},
     'sauce': {'allergens': ['peanuts', 'Egg'],
               'may_contain': ['wheat', 'Egg'],
               'uses': ['crust', 'topping']},
     'topping': {'allergens': ['Egg', 'wheat'], 'may_contain': ['eggs', ' sesame '], 'uses': []}},
    'base'],
   {'contains': ['egg', 'sesame', 'soy', 'wheat'], 'error': None, 'may_contain': ['milk']}],
  ['generated control 1',
   [{'base': {'allergens': ['tree nuts', 'dairy'],
              'may_contain': ['soy', ' sesame '],
              'uses': ['sauce', 'topping', 'mystery']},
     'crust': {'allergens': ['soy'], 'may_contain': [], 'uses': ['topping', 'mystery']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': ['milk'], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['milk', 'tree nuts'], 'uses': ['topping']},
     'topping': {'allergens': [], 'may_contain': ['dairy', 'milk'], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'unknown: mystery', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': [], 'may_contain': ['eggs'], 'uses': ['sauce', 'topping']},
     'crust': {'allergens': ['wheat'], 'may_contain': ['dairy'], 'uses': ['filling', 'topping', 'sauce']},
     'filling': {'allergens': [], 'may_contain': [' sesame ', 'eggs'], 'uses': []},
     'sauce': {'allergens': ['wheat', 'dairy'], 'may_contain': ['soy', 'wheat'], 'uses': ['filling', 'base']},
     'topping': {'allergens': [], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': []},
     'crust': {'allergens': ['dairy', 'peanuts'], 'may_contain': [], 'uses': ['filling', 'topping']},
     'filling': {'allergens': ['Egg'], 'may_contain': ['peanuts', 'dairy'], 'uses': ['topping']},
     'sauce': {'allergens': ['milk'], 'may_contain': ['soy', 'Egg'], 'uses': ['filling']},
     'topping': {'allergens': ['tree nuts', 'milk'], 'may_contain': ['soy', 'tree nuts'], 'uses': []}},
    'base'],
   {'contains': [], 'error': None, 'may_contain': ['tree nut']}]],
 [['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['unknown sub', [{'base': {'uses': ['ghost']}}, 'base'],
   {'contains': [], 'error': 'unknown: ghost', 'may_contain': []}],
  ['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['regression: contains precedence',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['sauce', 'crust', 'topping']},
     'crust': {'allergens': ['dairy', 'tree nuts'], 'may_contain': ['wheat'], 'uses': ['filling']},
     'filling': {'allergens': ['peanuts', 'wheat'], 'may_contain': ['Egg'], 'uses': []},
     'sauce': {'allergens': ['milk', 'soy'], 'may_contain': [], 'uses': ['crust']},
     'topping': {'allergens': [], 'may_contain': ['wheat', ' sesame '], 'uses': []}},
    'base'],
   {'contains': ['milk', 'peanut', 'soy', 'tree nut', 'wheat'],
    'error': None,
    'may_contain': ['egg', 'sesame']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [], 'may_contain': ['soy', 'eggs'], 'uses': ['sauce']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['filling']},
     'filling': {'allergens': ['Egg', 'milk'], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['peanuts'], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['dairy'], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': ['egg', 'milk'], 'error': None, 'may_contain': ['peanut', 'soy']}],
  ['generated control 1',
   [{'base': {'allergens': [' sesame ', 'eggs'], 'may_contain': [], 'uses': ['sauce', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['milk'], 'uses': ['topping', 'sauce']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': ['dairy', 'peanuts'], 'uses': []},
     'sauce': {'allergens': [], 'may_contain': [' sesame '], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['soy'], 'may_contain': ['tree nuts'], 'uses': ['base']}},
    'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': ['eggs', 'wheat'], 'may_contain': ['tree nuts'], 'uses': []},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'filling': {'allergens': [], 'may_contain': ['eggs'], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['dairy'], 'uses': ['filling', 'topping']},
     'topping': {'allergens': [], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'wheat'], 'error': None, 'may_contain': ['tree nut']}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': ['peanuts'], 'uses': ['sauce', 'crust']},
     'crust': {'allergens': ['tree nuts'], 'may_contain': [' sesame '], 'uses': ['topping']},
     'filling': {'allergens': [], 'may_contain': ['wheat'], 'uses': []},
     'sauce': {'allergens': ['dairy'], 'may_contain': [' sesame '], 'uses': ['crust', 'filling', 'topping']},
     'topping': {'allergens': [], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'tree nut'], 'error': None, 'may_contain': ['peanut', 'sesame', 'wheat']}]],
 [['unknown sub', [{'base': {'uses': ['ghost']}}, 'base'],
   {'contains': [], 'error': 'unknown: ghost', 'may_contain': []}],
  ['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': ['dairy'],
              'may_contain': [' sesame ', 'tree nuts'],
              'uses': ['sauce', 'filling', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': ['topping']},
     'filling': {'allergens': ['dairy', 'soy'], 'may_contain': [], 'uses': []},
     'sauce': {'allergens': ['milk'], 'may_contain': ['dairy', 'wheat'], 'uses': []},
     'topping': {'allergens': ['soy'], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['sesame', 'tree nut', 'wheat']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [' sesame '], 'may_contain': ['wheat', 'eggs'], 'uses': ['crust']},
     'crust': {'allergens': ['peanuts', 'Egg'], 'may_contain': ['wheat'], 'uses': []},
     'filling': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['wheat'], 'uses': ['filling', 'topping']},
     'topping': {'allergens': [], 'may_contain': ['soy', 'tree nuts'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'peanut', 'sesame'], 'error': None, 'may_contain': ['wheat']}],
  ['generated control 1',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['crust', 'topping', 'mystery']},
     'crust': {'allergens': [], 'may_contain': ['milk', 'eggs'], 'uses': ['filling', 'topping']},
     'filling': {'allergens': ['eggs', 'milk'], 'may_contain': ['dairy'], 'uses': []},
     'sauce': {'allergens': ['eggs'], 'may_contain': ['Egg'], 'uses': ['filling']},
     'topping': {'allergens': [], 'may_contain': ['Egg'], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'unknown: mystery', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': [], 'may_contain': [' sesame '], 'uses': ['sauce', 'crust']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': [], 'uses': ['topping', 'base']},
     'sauce': {'allergens': ['Egg', 'wheat'], 'may_contain': [' sesame '], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['tree nuts'], 'may_contain': ['peanuts'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'tree nut', 'wheat'], 'error': None, 'may_contain': ['peanut', 'sesame']}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['crust', 'filling']},
     'crust': {'allergens': [], 'may_contain': ['milk'], 'uses': ['filling', 'topping']},
     'filling': {'allergens': ['eggs', 'Egg'], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['crust', 'filling', 'topping', 'base']},
     'topping': {'allergens': ['peanuts'], 'may_contain': [], 'uses': ['crust']}},
    'base'],
   {'contains': [], 'error': 'cycle: crust', 'may_contain': []}]],
 [['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': [], 'may_contain': ['wheat', 'dairy'], 'uses': ['sauce', 'crust', 'filling']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': []},
     'filling': {'allergens': ['Egg', 'eggs'], 'may_contain': [' sesame '], 'uses': []},
     'sauce': {'allergens': ['dairy', 'tree nuts'], 'may_contain': ['dairy', ' sesame '], 'uses': []},
     'topping': {'allergens': ['Egg', 'peanuts'], 'may_contain': ['milk'], 'uses': ['base']}},
    'base'],
   {'contains': ['egg', 'milk', 'tree nut'], 'error': None, 'may_contain': ['sesame', 'wheat']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [], 'may_contain': ['soy'], 'uses': ['sauce', 'filling']},
     'crust': {'allergens': ['milk'], 'may_contain': [' sesame '], 'uses': ['topping']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': [], 'uses': []},
     'sauce': {'allergens': ['milk'],
               'may_contain': ['wheat', 'eggs'],
               'uses': ['crust', 'filling', 'topping']},
     'topping': {'allergens': ['soy'], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': ['milk', 'soy', 'tree nut'], 'error': None, 'may_contain': ['egg', 'sesame', 'wheat']}],
  ['generated control 1',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['sauce', 'crust']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['filling', 'base']},
     'filling': {'allergens': ['dairy'], 'may_contain': ['wheat'], 'uses': []},
     'sauce': {'allergens': ['eggs'],
               'may_contain': ['tree nuts', 'Egg'],
               'uses': ['filling', 'topping', 'base']},
     'topping': {'allergens': ['milk'], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': ['Egg'], 'may_contain': ['eggs'], 'uses': ['sauce', 'crust', 'mystery']},
     'crust': {'allergens': ['dairy'], 'may_contain': ['Egg'], 'uses': ['topping']},
     'filling': {'allergens': ['Egg', 'tree nuts'], 'may_contain': [' sesame ', 'soy'], 'uses': []},
     'sauce': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['crust', 'base']},
     'topping': {'allergens': ['tree nuts'], 'may_contain': [], 'uses': ['crust']}},
    'base'],
   {'contains': [], 'error': 'cycle: crust', 'may_contain': []}],
  ['generated control 3',
   [{'base': {'allergens': ['wheat', 'peanuts'],
              'may_contain': [' sesame ', 'peanuts'],
              'uses': ['crust', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['Egg'], 'uses': ['filling']},
     'filling': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['dairy', 'peanuts'], 'uses': ['crust']},
     'topping': {'allergens': ['wheat', 'peanuts'], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': ['peanut', 'wheat'], 'error': None, 'may_contain': ['egg', 'sesame']}]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
flat recipe{'contains': ['milk'], 'error': None, 'may_contain': ['soy']}{'contains': ['milk'], 'error': None, 'may_contain': ['soy']}Passed
diamond sharing{'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}{'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}Passed
cycle{'contains': [], 'error': 'cycle: base', 'may_contain': []}{'contains': [], 'error': 'cycle: base', 'may_contain': []}Passed
regression: contains precedence{'contains': ['milk', 'peanut', 'soy'], 'error': None, 'may_contain': ['egg', 'milk', 'wheat']}{'contains': ['milk', 'peanut', 'soy'], 'error': None, 'may_contain': ['egg', 'wheat']}Failed
repair check: contains precedence{'contains': ['egg', 'milk', 'peanut', 'tree nut', 'wheat'], 'error': None, 'may_contain': ['egg', 'milk', 'sesame', 'soy']}{'contains': ['egg', 'milk', 'peanut', 'tree nut', 'wheat'], 'error': None, 'may_contain': ['sesame', 'soy']}Failed
generated control 1{'contains': [], 'error': None, 'may_contain': []}{'contains': [], 'error': None, 'may_contain': []}Passed
generated control 2{'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['egg']}{'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['egg']}Passed
generated control 3{'contains': [], 'error': None, 'may_contain': ['milk', 'sesame']}{'contains': [], 'error': None, 'may_contain': ['milk', 'sesame']}Passed

SHA-256 / d33856c9fafa315636a08169c5ba3b3ee6f7cb2e5165121daa45cc0bd4d6c69d

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(recipes, root):
    SYN = {'dairy': 'milk', 'peanuts': 'peanut', 'tree nuts': 'tree nut', 'eggs': 'egg'}
    def canon(a):
        a = a.strip().lower()
        return SYN.get(a, a)
    contains, may = set(), set()
    state = {}
    def visit(n):
        if n not in recipes:
            return 'unknown: ' + n
        if state.get(n) == 1:
            return 'cycle: ' + n
        if state.get(n) == 2:
            return None
        state[n] = 1
        r = recipes[n]
        contains.update(canon(a) for a in r.get('allergens', []))
        may.update(canon(a) for a in r.get('may_contain', []))
        for s in r.get('uses', []):
            e = visit(s)
            if e:
                return e
        state[n] = 2
        return None
    err = visit(root)
    if err:
        return {'contains': [], 'may_contain': [], 'error': err}
    return {'contains': sorted(contains), 'may_contain': sorted(may - contains), 'error': None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': ['soy'], 'may_contain': ['dairy', 'Egg'], 'uses': ['topping']},
     'crust': {'allergens': ['tree nuts', 'dairy'], 'may_contain': ['wheat'], 'uses': []},
     'filling': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': []},
     'sauce': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': ['filling', 'base']},
     'topping': {'allergens': ['peanuts', 'milk'], 'may_contain': ['wheat', 'milk'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'peanut', 'soy'], 'error': None, 'may_contain': ['egg', 'wheat']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [],
              'may_contain': ['dairy', ' sesame '],
              'uses': ['sauce', 'crust', 'filling', 'topping']},
     'crust': {'allergens': ['tree nuts'], 'may_contain': ['soy', 'Egg'], 'uses': []},
     'filling': {'allergens': ['wheat', 'peanuts'], 'may_contain': [], 'uses': []},
     'sauce': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['wheat', 'Egg'], 'may_contain': ['Egg'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'milk', 'peanut', 'tree nut', 'wheat'],
    'error': None,
    'may_contain': ['sesame', 'soy']}],
  ['generated control 1',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'crust': {'allergens': ['wheat'], 'may_contain': ['wheat'], 'uses': []},
     'filling': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': ['milk'], 'may_contain': ['peanuts'], 'uses': ['crust']},
     'topping': {'allergens': [], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': [], 'error': None, 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['filling']},
     'crust': {'allergens': ['soy'], 'may_contain': ['soy'], 'uses': ['topping']},
     'filling': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': ['soy', 'dairy'], 'may_contain': ['Egg'], 'uses': ['crust', 'filling']},
     'topping': {'allergens': ['soy', 'dairy'], 'may_contain': ['eggs'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['egg']}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': ['milk', ' sesame '], 'uses': []},
     'crust': {'allergens': ['wheat', 'tree nuts'], 'may_contain': ['milk'], 'uses': ['filling']},
     'filling': {'allergens': ['tree nuts', 'soy'], 'may_contain': [' sesame ', 'wheat'], 'uses': ['sauce']},
     'sauce': {'allergens': ['wheat', 'tree nuts'], 'may_contain': ['Egg'], 'uses': ['crust', 'filling']},
     'topping': {'allergens': ['dairy'], 'may_contain': ['dairy', 'eggs'], 'uses': []}},
    'base'],
   {'contains': [], 'error': None, 'may_contain': ['milk', 'sesame']}]],
 [['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['unknown sub', [{'base': {'uses': ['ghost']}}, 'base'],
   {'contains': [], 'error': 'unknown: ghost', 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': ['wheat'],
              'may_contain': ['milk'],
              'uses': ['sauce', 'crust', 'filling', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['dairy', 'Egg'], 'uses': ['filling']},
     'filling': {'allergens': ['eggs', 'peanuts'], 'may_contain': ['tree nuts', 'milk'], 'uses': []},
     'sauce': {'allergens': ['peanuts', 'wheat'],
               'may_contain': ['milk', 'wheat'],
               'uses': ['crust', 'topping']},
     'topping': {'allergens': ['eggs', ' sesame '], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'peanut', 'sesame', 'wheat'], 'error': None, 'may_contain': ['milk', 'tree nut']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': ['soy'], 'may_contain': ['dairy', 'milk'], 'uses': ['filling', 'topping']},
     'crust': {'allergens': ['wheat', 'peanuts'], 'may_contain': [' sesame '], 'uses': []},
     'filling': {'allergens': [' sesame '], 'may_contain': ['soy'], 'uses': ['topping']},
     'sauce': {'allergens': ['peanuts', 'Egg'],
               'may_contain': ['wheat', 'Egg'],
               'uses': ['crust', 'topping']},
     'topping': {'allergens': ['Egg', 'wheat'], 'may_contain': ['eggs', ' sesame '], 'uses': []}},
    'base'],
   {'contains': ['egg', 'sesame', 'soy', 'wheat'], 'error': None, 'may_contain': ['milk']}],
  ['generated control 1',
   [{'base': {'allergens': ['tree nuts', 'dairy'],
              'may_contain': ['soy', ' sesame '],
              'uses': ['sauce', 'topping', 'mystery']},
     'crust': {'allergens': ['soy'], 'may_contain': [], 'uses': ['topping', 'mystery']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': ['milk'], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['milk', 'tree nuts'], 'uses': ['topping']},
     'topping': {'allergens': [], 'may_contain': ['dairy', 'milk'], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'unknown: mystery', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': [], 'may_contain': ['eggs'], 'uses': ['sauce', 'topping']},
     'crust': {'allergens': ['wheat'], 'may_contain': ['dairy'], 'uses': ['filling', 'topping', 'sauce']},
     'filling': {'allergens': [], 'may_contain': [' sesame ', 'eggs'], 'uses': []},
     'sauce': {'allergens': ['wheat', 'dairy'], 'may_contain': ['soy', 'wheat'], 'uses': ['filling', 'base']},
     'topping': {'allergens': [], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': []},
     'crust': {'allergens': ['dairy', 'peanuts'], 'may_contain': [], 'uses': ['filling', 'topping']},
     'filling': {'allergens': ['Egg'], 'may_contain': ['peanuts', 'dairy'], 'uses': ['topping']},
     'sauce': {'allergens': ['milk'], 'may_contain': ['soy', 'Egg'], 'uses': ['filling']},
     'topping': {'allergens': ['tree nuts', 'milk'], 'may_contain': ['soy', 'tree nuts'], 'uses': []}},
    'base'],
   {'contains': [], 'error': None, 'may_contain': ['tree nut']}]],
 [['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['unknown sub', [{'base': {'uses': ['ghost']}}, 'base'],
   {'contains': [], 'error': 'unknown: ghost', 'may_contain': []}],
  ['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['regression: contains precedence',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['sauce', 'crust', 'topping']},
     'crust': {'allergens': ['dairy', 'tree nuts'], 'may_contain': ['wheat'], 'uses': ['filling']},
     'filling': {'allergens': ['peanuts', 'wheat'], 'may_contain': ['Egg'], 'uses': []},
     'sauce': {'allergens': ['milk', 'soy'], 'may_contain': [], 'uses': ['crust']},
     'topping': {'allergens': [], 'may_contain': ['wheat', ' sesame '], 'uses': []}},
    'base'],
   {'contains': ['milk', 'peanut', 'soy', 'tree nut', 'wheat'],
    'error': None,
    'may_contain': ['egg', 'sesame']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [], 'may_contain': ['soy', 'eggs'], 'uses': ['sauce']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['filling']},
     'filling': {'allergens': ['Egg', 'milk'], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['peanuts'], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['dairy'], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': ['egg', 'milk'], 'error': None, 'may_contain': ['peanut', 'soy']}],
  ['generated control 1',
   [{'base': {'allergens': [' sesame ', 'eggs'], 'may_contain': [], 'uses': ['sauce', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['milk'], 'uses': ['topping', 'sauce']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': ['dairy', 'peanuts'], 'uses': []},
     'sauce': {'allergens': [], 'may_contain': [' sesame '], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['soy'], 'may_contain': ['tree nuts'], 'uses': ['base']}},
    'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': ['eggs', 'wheat'], 'may_contain': ['tree nuts'], 'uses': []},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'filling': {'allergens': [], 'may_contain': ['eggs'], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['dairy'], 'uses': ['filling', 'topping']},
     'topping': {'allergens': [], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'wheat'], 'error': None, 'may_contain': ['tree nut']}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': ['peanuts'], 'uses': ['sauce', 'crust']},
     'crust': {'allergens': ['tree nuts'], 'may_contain': [' sesame '], 'uses': ['topping']},
     'filling': {'allergens': [], 'may_contain': ['wheat'], 'uses': []},
     'sauce': {'allergens': ['dairy'], 'may_contain': [' sesame '], 'uses': ['crust', 'filling', 'topping']},
     'topping': {'allergens': [], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'tree nut'], 'error': None, 'may_contain': ['peanut', 'sesame', 'wheat']}]],
 [['unknown sub', [{'base': {'uses': ['ghost']}}, 'base'],
   {'contains': [], 'error': 'unknown: ghost', 'may_contain': []}],
  ['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': ['dairy'],
              'may_contain': [' sesame ', 'tree nuts'],
              'uses': ['sauce', 'filling', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['tree nuts'], 'uses': ['topping']},
     'filling': {'allergens': ['dairy', 'soy'], 'may_contain': [], 'uses': []},
     'sauce': {'allergens': ['milk'], 'may_contain': ['dairy', 'wheat'], 'uses': []},
     'topping': {'allergens': ['soy'], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['sesame', 'tree nut', 'wheat']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [' sesame '], 'may_contain': ['wheat', 'eggs'], 'uses': ['crust']},
     'crust': {'allergens': ['peanuts', 'Egg'], 'may_contain': ['wheat'], 'uses': []},
     'filling': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['wheat'], 'uses': ['filling', 'topping']},
     'topping': {'allergens': [], 'may_contain': ['soy', 'tree nuts'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'peanut', 'sesame'], 'error': None, 'may_contain': ['wheat']}],
  ['generated control 1',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['crust', 'topping', 'mystery']},
     'crust': {'allergens': [], 'may_contain': ['milk', 'eggs'], 'uses': ['filling', 'topping']},
     'filling': {'allergens': ['eggs', 'milk'], 'may_contain': ['dairy'], 'uses': []},
     'sauce': {'allergens': ['eggs'], 'may_contain': ['Egg'], 'uses': ['filling']},
     'topping': {'allergens': [], 'may_contain': ['Egg'], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'unknown: mystery', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': [], 'may_contain': [' sesame '], 'uses': ['sauce', 'crust']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': [], 'uses': ['topping', 'base']},
     'sauce': {'allergens': ['Egg', 'wheat'], 'may_contain': [' sesame '], 'uses': ['crust', 'topping']},
     'topping': {'allergens': ['tree nuts'], 'may_contain': ['peanuts'], 'uses': []}},
    'base'],
   {'contains': ['egg', 'tree nut', 'wheat'], 'error': None, 'may_contain': ['peanut', 'sesame']}],
  ['generated control 3',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['crust', 'filling']},
     'crust': {'allergens': [], 'may_contain': ['milk'], 'uses': ['filling', 'topping']},
     'filling': {'allergens': ['eggs', 'Egg'], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['crust', 'filling', 'topping', 'base']},
     'topping': {'allergens': ['peanuts'], 'may_contain': [], 'uses': ['crust']}},
    'base'],
   {'contains': [], 'error': 'cycle: crust', 'may_contain': []}]],
 [['flat recipe', [{'base': {'allergens': ['milk'], 'may_contain': ['soy'], 'uses': []}}, 'base'],
   {'contains': ['milk'], 'error': None, 'may_contain': ['soy']}],
  ['diamond sharing',
   [{'a': {'allergens': ['wheat'], 'uses': ['c']},
     'b': {'allergens': [], 'uses': ['c']},
     'base': {'allergens': [], 'uses': ['a', 'b']},
     'c': {'allergens': ['Dairy'], 'uses': []}},
    'base'],
   {'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}],
  ['cycle', [{'a': {'uses': ['base']}, 'base': {'uses': ['a']}}, 'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['regression: contains precedence',
   [{'base': {'allergens': [], 'may_contain': ['wheat', 'dairy'], 'uses': ['sauce', 'crust', 'filling']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': []},
     'filling': {'allergens': ['Egg', 'eggs'], 'may_contain': [' sesame '], 'uses': []},
     'sauce': {'allergens': ['dairy', 'tree nuts'], 'may_contain': ['dairy', ' sesame '], 'uses': []},
     'topping': {'allergens': ['Egg', 'peanuts'], 'may_contain': ['milk'], 'uses': ['base']}},
    'base'],
   {'contains': ['egg', 'milk', 'tree nut'], 'error': None, 'may_contain': ['sesame', 'wheat']}],
  ['repair check: contains precedence',
   [{'base': {'allergens': [], 'may_contain': ['soy'], 'uses': ['sauce', 'filling']},
     'crust': {'allergens': ['milk'], 'may_contain': [' sesame '], 'uses': ['topping']},
     'filling': {'allergens': ['tree nuts'], 'may_contain': [], 'uses': []},
     'sauce': {'allergens': ['milk'],
               'may_contain': ['wheat', 'eggs'],
               'uses': ['crust', 'filling', 'topping']},
     'topping': {'allergens': ['soy'], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': ['milk', 'soy', 'tree nut'], 'error': None, 'may_contain': ['egg', 'sesame', 'wheat']}],
  ['generated control 1',
   [{'base': {'allergens': [], 'may_contain': [], 'uses': ['sauce', 'crust']},
     'crust': {'allergens': [], 'may_contain': [], 'uses': ['filling', 'base']},
     'filling': {'allergens': ['dairy'], 'may_contain': ['wheat'], 'uses': []},
     'sauce': {'allergens': ['eggs'],
               'may_contain': ['tree nuts', 'Egg'],
               'uses': ['filling', 'topping', 'base']},
     'topping': {'allergens': ['milk'], 'may_contain': ['wheat'], 'uses': []}},
    'base'],
   {'contains': [], 'error': 'cycle: base', 'may_contain': []}],
  ['generated control 2',
   [{'base': {'allergens': ['Egg'], 'may_contain': ['eggs'], 'uses': ['sauce', 'crust', 'mystery']},
     'crust': {'allergens': ['dairy'], 'may_contain': ['Egg'], 'uses': ['topping']},
     'filling': {'allergens': ['Egg', 'tree nuts'], 'may_contain': [' sesame ', 'soy'], 'uses': []},
     'sauce': {'allergens': ['dairy'], 'may_contain': [], 'uses': ['crust', 'base']},
     'topping': {'allergens': ['tree nuts'], 'may_contain': [], 'uses': ['crust']}},
    'base'],
   {'contains': [], 'error': 'cycle: crust', 'may_contain': []}],
  ['generated control 3',
   [{'base': {'allergens': ['wheat', 'peanuts'],
              'may_contain': [' sesame ', 'peanuts'],
              'uses': ['crust', 'topping']},
     'crust': {'allergens': [], 'may_contain': ['Egg'], 'uses': ['filling']},
     'filling': {'allergens': [], 'may_contain': [], 'uses': ['topping']},
     'sauce': {'allergens': [], 'may_contain': ['dairy', 'peanuts'], 'uses': ['crust']},
     'topping': {'allergens': ['wheat', 'peanuts'], 'may_contain': [], 'uses': []}},
    'base'],
   {'contains': ['peanut', 'wheat'], 'error': None, 'may_contain': ['egg', 'sesame']}]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
flat recipe{'contains': ['milk'], 'error': None, 'may_contain': ['soy']}{'contains': ['milk'], 'error': None, 'may_contain': ['soy']}Passed
diamond sharing{'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}{'contains': ['milk', 'wheat'], 'error': None, 'may_contain': []}Passed
cycle{'contains': [], 'error': 'cycle: base', 'may_contain': []}{'contains': [], 'error': 'cycle: base', 'may_contain': []}Passed
regression: contains precedence{'contains': ['milk', 'peanut', 'soy'], 'error': None, 'may_contain': ['egg', 'wheat']}{'contains': ['milk', 'peanut', 'soy'], 'error': None, 'may_contain': ['egg', 'wheat']}Passed
repair check: contains precedence{'contains': ['egg', 'milk', 'peanut', 'tree nut', 'wheat'], 'error': None, 'may_contain': ['sesame', 'soy']}{'contains': ['egg', 'milk', 'peanut', 'tree nut', 'wheat'], 'error': None, 'may_contain': ['sesame', 'soy']}Passed
generated control 1{'contains': [], 'error': None, 'may_contain': []}{'contains': [], 'error': None, 'may_contain': []}Passed
generated control 2{'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['egg']}{'contains': ['milk', 'soy'], 'error': None, 'may_contain': ['egg']}Passed
generated control 3{'contains': [], 'error': None, 'may_contain': ['milk', 'sesame']}{'contains': [], 'error': None, 'may_contain': ['milk', 'sesame']}Passed

SHA-256 / aac2c727538a69cb83c822baa101f5e8168b7859fb0abbca6a304804d47702c2

Verification & scope

A deterministic toy contract stated in full here; it is a bounded teaching model, not an authoritative reference or standards implementation. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:52:30.300218+00:00.

Case digest / bdac07ab647073b7cf2e23ff5fd6bb7994a3991432509f92177a81b1afc8689a