nodes = {row['id']: row for row in output['nodes']}
def run(record):
    node, seen = nodes['root'], set()
    while not node.get('terminal'):
        if node['id'] in seen:
            raise ValueError('Decision tree cycle')
        seen.add(node['id'])
        question = node['question']
        if '订单' in question or 'order' in question:
            answer = bool(record.get('order_id'))
        elif '未收货' in question:
            answer = not record.get('received', False)
        else:
            answer = record.get('received', False)
        target = node['yes' if answer else 'no']
        node = nodes[target] if target in nodes else {'terminal': target}
    return node['terminal']
terminals = [run(row) for row in data['cases']]
check('三条真实规则路径分别到正确出口', terminals == ['human', 'logistics', 'aftersales'])
result = {'nodes': output['nodes'], 'tested_terminals': terminals}
