from __future__ import annotations

import gc
import inspect
import os
import time
from pathlib import Path

import dill as pickle
import pytest
from inference.core.workflows.core_steps.composition.workflow_caller.v1 import (
    _build_kind_name_map, _convert_output_descriptions_to_kinds)
from inference.core.workflows.execution_engine.entities.types import (
    BOOLEAN_KIND, CLASSIFICATION_PREDICTION_KIND, DETECTION_KIND,
    DICTIONARY_KIND, FLOAT_KIND, IMAGE_KIND, INTEGER_KIND, STRING_KIND,
    WILDCARD_KIND, Kind)


def codeflash_wrap(codeflash_wrapped, codeflash_test_module_name, codeflash_test_class_name, codeflash_test_name, codeflash_function_name, codeflash_line_id, codeflash_loop_index, *args, **kwargs):
    test_id = f'{codeflash_test_module_name}:{codeflash_test_class_name}:{codeflash_test_name}:{codeflash_line_id}:{codeflash_loop_index}'
    if not hasattr(codeflash_wrap, 'index'):
        codeflash_wrap.index = {}
    if test_id in codeflash_wrap.index:
        codeflash_wrap.index[test_id] += 1
    else:
        codeflash_wrap.index[test_id] = 0
    codeflash_test_index = codeflash_wrap.index[test_id]
    invocation_id = f'{codeflash_line_id}_{codeflash_test_index}'
    test_stdout_tag = f"{codeflash_test_module_name}:{(codeflash_test_class_name + '.' if codeflash_test_class_name else '')}{codeflash_test_name}:{codeflash_function_name}:{codeflash_loop_index}:{invocation_id}"
    print(f'!$######{test_stdout_tag}######$!')
    exception = None
    gc.disable()
    try:
        counter = time.perf_counter_ns()
        return_value = codeflash_wrapped(*args, **kwargs)
        codeflash_duration = time.perf_counter_ns() - counter
    except Exception as e:
        codeflash_duration = time.perf_counter_ns() - counter
        exception = e
    gc.enable()
    print(f'!######{test_stdout_tag}######!')
    iteration = os.environ['CODEFLASH_TEST_ITERATION']
    with Path('{codeflash_run_tmp_dir_client_side}', f'test_return_values_{iteration}.bin').open('ab') as f:
        pickled_values = pickle.dumps((args, kwargs, exception)) if exception else pickle.dumps((args, kwargs, return_value))
        _test_name = f"{codeflash_test_module_name}:{(codeflash_test_class_name + '.' if codeflash_test_class_name else '')}{codeflash_test_name}:{codeflash_function_name}:{codeflash_line_id}".encode('ascii')
        f.write(len(_test_name).to_bytes(4, byteorder='big'))
        f.write(_test_name)
        f.write(codeflash_duration.to_bytes(8, byteorder='big'))
        f.write(len(pickled_values).to_bytes(4, byteorder='big'))
        f.write(pickled_values)
        f.write(codeflash_loop_index.to_bytes(8, byteorder='big'))
        f.write(len(invocation_id).to_bytes(4, byteorder='big'))
        f.write(invocation_id.encode('ascii'))
    if exception:
        raise exception
    return return_value

def test_convert_simple_list_of_kinds():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion of a simple list of kind names to Kind objects.'
    outputs_description = {'prediction': ['image']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_simple_list_of_kinds', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_multiple_kinds_in_list():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion of multiple kind names in a single list.'
    outputs_description = {'output1': ['image', 'string', 'boolean']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_multiple_kinds_in_list', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    kind_names = {kind.name for kind in result['output1']}

def test_convert_dict_selector_to_dictionary_kind():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that dict-based selectors (wildcard) are converted to DICTIONARY_KIND.'
    outputs_description = {'dynamic_output': {'step_name': ['image', 'string']}}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_dict_selector_to_dictionary_kind', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_multiple_outputs():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion of multiple outputs with different kinds.'
    outputs_description = {'output1': ['image'], 'output2': ['string', 'boolean'], 'output3': ['integer', 'float']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_multiple_outputs', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_empty_kind_list_defaults_to_wildcard():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that empty kind lists default to WILDCARD_KIND.'
    outputs_description = {'output1': []}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_empty_kind_list_defaults_to_wildcard', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_unknown_kind_names_filtered():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that unknown kind names are filtered out.'
    outputs_description = {'output1': ['image', 'unknown_kind_xyz', 'string']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_unknown_kind_names_filtered', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    kind_names = {kind.name for kind in result['output1']}

def test_convert_all_unknown_kinds_defaults_to_wildcard():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that all-unknown kind lists default to WILDCARD_KIND.'
    outputs_description = {'output1': ['unknown1', 'unknown2', 'unknown3']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_all_unknown_kinds_defaults_to_wildcard', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_build_kind_name_map_contains_known_kinds():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that _build_kind_name_map returns a dict with known kind names.'
    kind_map = _build_kind_name_map()

def test_build_kind_name_map_caching():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that _build_kind_name_map returns the same object on repeated calls.'
    map1 = _build_kind_name_map()
    map2 = _build_kind_name_map()

def test_convert_empty_outputs_description():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion of an empty outputs description dict.'
    outputs_description = {}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_empty_outputs_description', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_single_kind_in_output():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion with only one kind name.'
    outputs_description = {'output': ['image']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_single_kind_in_output', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_output_name_with_special_characters():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that output names with special characters are preserved.'
    outputs_description = {'output_with-special.chars@123': ['image']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_output_name_with_special_characters', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_duplicate_kind_names_in_list():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that duplicate kind names in a list are preserved.'
    outputs_description = {'output': ['image', 'image', 'string']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_duplicate_kind_names_in_list', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    image_count = sum((1 for k in result['output'] if k.name == 'image'))

def test_convert_dict_selector_with_empty_inner_dict():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test dict selectors with empty inner dict.'
    outputs_description = {'output': {}}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_dict_selector_with_empty_inner_dict', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_dict_selector_with_multiple_keys():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test dict selectors with multiple keys in the inner dict.'
    outputs_description = {'output': {'step1': ['image'], 'step2': ['string', 'boolean'], 'step3': []}}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_dict_selector_with_multiple_keys', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_mixed_outputs_dict_and_list():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion of mixed output types (both dict and list kinds).'
    outputs_description = {'list_output': ['image', 'string'], 'dict_output': {'step': ['detection']}, 'empty_list_output': []}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_mixed_outputs_dict_and_list', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_kind_name_case_sensitivity():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that kind name matching is case-sensitive.'
    outputs_description = {'output': ['image', 'Image', 'IMAGE']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_kind_name_case_sensitivity', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_whitespace_in_kind_names():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that kind names with whitespace are treated as unknown.'
    outputs_description = {'output': ['image', ' image', 'image ', ' image ']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_whitespace_in_kind_names', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_very_long_output_name():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion with very long output names.'
    long_name = 'a' * 1000
    outputs_description = {long_name: ['image']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_very_long_output_name', '_convert_output_descriptions_to_kinds', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_numeric_string_output_name():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion with numeric string as output name.'
    outputs_description = {'123': ['image'], '456': ['string']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_numeric_string_output_name', '_convert_output_descriptions_to_kinds', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_many_outputs():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion with a large number of outputs.'
    outputs_description = {}
    for i in range(500):
        outputs_description[f'output_{i}'] = ['image', 'string', 'boolean']
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_many_outputs', '_convert_output_descriptions_to_kinds', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_many_kinds_per_output():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion with many kinds in a single output.'
    kind_map = _build_kind_name_map()
    kind_names = list(kind_map.keys())
    outputs_description = {'output': kind_names}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_many_kinds_per_output', '_convert_output_descriptions_to_kinds', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_convert_many_dict_selectors():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion with many dict selector outputs.'
    outputs_description = {}
    for i in range(300):
        outputs_description[f'dynamic_{i}'] = {f'step_{j}': ['image', 'string'] for j in range(5)}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_many_dict_selectors', '_convert_output_descriptions_to_kinds', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i in range(300):
        pass

def test_convert_mixed_known_and_unknown_kinds_large_scale():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion with mix of known and unknown kinds at scale.'
    outputs_description = {}
    for i in range(200):
        outputs_description[f'output_{i}'] = ['image', f'unknown_{i}', 'string', f'fake_kind_{i}', 'boolean']
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_mixed_known_and_unknown_kinds_large_scale', '_convert_output_descriptions_to_kinds', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i in range(200):
        kind_names = {k.name for k in result[f'output_{i}']}

def test_convert_all_unknown_kinds_large_scale():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that large-scale all-unknown inputs default to WILDCARD_KIND.'
    outputs_description = {}
    for i in range(100):
        outputs_description[f'output_{i}'] = [f'unknown_a_{i}', f'unknown_b_{i}', f'unknown_c_{i}']
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_all_unknown_kinds_large_scale', '_convert_output_descriptions_to_kinds', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i in range(100):
        pass

def test_convert_empty_lists_large_scale():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test large-scale conversion of empty kind lists.'
    outputs_description = {}
    for i in range(250):
        outputs_description[f'output_{i}'] = []
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_empty_lists_large_scale', '_convert_output_descriptions_to_kinds', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i in range(250):
        pass

def test_convert_alternating_dict_and_list_outputs_large_scale():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test large-scale conversion with alternating dict and list outputs.'
    outputs_description = {}
    for i in range(1000):
        if i % 2 == 0:
            outputs_description[f'output_{i}'] = ['image', 'string']
        else:
            outputs_description[f'output_{i}'] = {'step': ['image']}
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_alternating_dict_and_list_outputs_large_scale', '_convert_output_descriptions_to_kinds', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i in range(1000):
        if i % 2 == 0:
            pass
        else:
            pass

def test_convert_complex_nested_dict_selectors():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test conversion with complex nested dict structures at scale.'
    outputs_description = {}
    for i in range(50):
        nested_dict = {}
        for j in range(20):
            nested_dict[f'step_{j}'] = ['image', 'string', 'boolean', 'detection']
        outputs_description[f'dynamic_{i}'] = nested_dict
    _call__bound__arguments = inspect.signature(_convert_output_descriptions_to_kinds).bind(outputs_description)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_convert_output_descriptions_to_kinds, 'tests.inference.unit_tests.test__convert_output_descriptions_to_kinds__unit_test_1', None, 'test_convert_complex_nested_dict_selectors', '_convert_output_descriptions_to_kinds', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i in range(50):
        pass