from __future__ import annotations

import gc
import inspect
import os
import time
from pathlib import Path
from typing import List, Optional

import dill as pickle
import pytest
from inference.core.workflows.core_steps.common.query_language.entities.introspection import \
    OperationDescription
from inference.core.workflows.core_steps.common.query_language.introspection.core import (
    _get_property_name_options, _ref_to_def_name,
    prepare_operations_descriptions)
from inference.core.workflows.execution_engine.entities.types import 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_prepare_operations_descriptions_returns_list():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that prepare_operations_descriptions returns a list.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_returns_list', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_prepare_operations_descriptions_returns_operation_descriptions():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that all items in the result are OperationDescription instances.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_returns_operation_descriptions', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for item in result:
        pass

def test_prepare_operations_descriptions_operation_type_is_string():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that operation_type field is a non-empty string.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_operation_type_is_string', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for desc in result:
        pass

def test_prepare_operations_descriptions_compound_is_bool():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that compound field is a boolean.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_compound_is_bool', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for desc in result:
        pass

def test_prepare_operations_descriptions_input_kind_is_list():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that input_kind field is a list.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_input_kind_is_list', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for desc in result:
        pass

def test_prepare_operations_descriptions_output_kind_is_list():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that output_kind field is a list.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_output_kind_is_list', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for desc in result:
        pass

def test_prepare_operations_descriptions_nested_operation_fields():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that nested operation fields are None or lists.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_nested_operation_fields', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for desc in result:
        pass

def test_prepare_operations_descriptions_property_name_options():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that property_name_options is None or a list of strings.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_property_name_options', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for desc in result:
        if desc.property_name_options is not None:
            for option in desc.property_name_options:
                pass

def test_ref_to_def_name_with_valid_ref():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name with a valid $ref schema.'
    schema = {'$ref': '#/$defs/MyType'}
    result = _ref_to_def_name(schema)

def test_ref_to_def_name_with_nested_path():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name with nested path in $ref.'
    schema = {'$ref': '#/some/nested/path/MyOperation'}
    result = _ref_to_def_name(schema)

def test_ref_to_def_name_with_missing_ref():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name returns None when $ref is missing.'
    schema = {'type': 'object'}
    result = _ref_to_def_name(schema)

def test_ref_to_def_name_with_empty_schema():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name with an empty schema.'
    schema = {}
    result = _ref_to_def_name(schema)

def test_ref_to_def_name_with_custom_ref_key():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name with custom ref_key parameter.'
    schema = {'customRef': '#/$defs/CustomType'}
    result = _ref_to_def_name(schema, ref_key='customRef')

def test_get_property_name_options_with_enum_in_ref():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options resolves enum from referenced definition.'
    type_definition = {'properties': {'property_name': {'$ref': '#/$defs/PropertyEnum'}}}
    defs = {'PropertyEnum': {'enum': ['size', 'height', 'width']}}
    result = _get_property_name_options(type_definition, defs)

def test_get_property_name_options_with_direct_enum():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options with direct enum in property_name schema.'
    type_definition = {'properties': {'property_name': {'enum': ['prop1', 'prop2', 'prop3']}}}
    defs = {}
    result = _get_property_name_options(type_definition, defs)

def test_get_property_name_options_with_missing_property_name():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options returns None when property_name is missing.'
    type_definition = {'properties': {'other_field': {'type': 'string'}}}
    defs = {}
    result = _get_property_name_options(type_definition, defs)

def test_get_property_name_options_with_empty_properties():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options with empty properties dict.'
    type_definition = {'properties': {}}
    defs = {}
    result = _get_property_name_options(type_definition, defs)

def test_get_property_name_options_with_missing_properties():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options when properties key is missing.'
    type_definition = {}
    defs = {}
    result = _get_property_name_options(type_definition, defs)

def test_prepare_operations_descriptions_idempotent():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that calling prepare_operations_descriptions multiple times returns consistent results.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_idempotent', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result1 = codeflash_output
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_idempotent', 'prepare_operations_descriptions', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result2 = codeflash_output
    for desc1, desc2 in zip(result1, result2):
        pass

def test_prepare_operations_descriptions_no_duplicate_operation_types():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that there are no duplicate operation_type values.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_no_duplicate_operation_types', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    operation_types = [desc.operation_type for desc in result]

def test_ref_to_def_name_with_single_slash():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name with path containing only one slash.'
    schema = {'$ref': 'Type'}
    result = _ref_to_def_name(schema)

def test_ref_to_def_name_with_empty_ref_string():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name with empty $ref string.'
    schema = {'$ref': ''}
    result = _ref_to_def_name(schema)

def test_ref_to_def_name_with_trailing_slash():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name with trailing slash in $ref.'
    schema = {'$ref': '#/$defs/MyType/'}
    result = _ref_to_def_name(schema)

def test_get_property_name_options_with_ref_not_in_defs():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options when referenced definition is not in defs.'
    type_definition = {'properties': {'property_name': {'$ref': '#/$defs/NonExistentType'}}}
    defs = {}
    result = _get_property_name_options(type_definition, defs)

def test_get_property_name_options_with_ref_without_enum():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options when referenced definition has no enum.'
    type_definition = {'properties': {'property_name': {'$ref': '#/$defs/SomeType'}}}
    defs = {'SomeType': {'type': 'object', 'properties': {'field': {'type': 'string'}}}}
    result = _get_property_name_options(type_definition, defs)

def test_get_property_name_options_with_empty_enum():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options with empty enum list.'
    type_definition = {'properties': {'property_name': {'enum': []}}}
    defs = {}
    result = _get_property_name_options(type_definition, defs)

def test_get_property_name_options_with_single_enum_value():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options with single enum value.'
    type_definition = {'properties': {'property_name': {'enum': ['single']}}}
    defs = {}
    result = _get_property_name_options(type_definition, defs)

def test_prepare_operations_descriptions_all_fields_present():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that all required fields are present in each OperationDescription.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_all_fields_present', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    required_fields = ['operation_type', 'compound', 'input_kind', 'output_kind']
    for desc in result:
        for field in required_fields:
            pass

def test_prepare_operations_descriptions_operation_types_are_unique_strings():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that all operation_type values are non-empty unique strings.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_operation_types_are_unique_strings', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    operation_types = [desc.operation_type for desc in result]

def test_ref_to_def_name_with_special_characters():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name with special characters in definition name.'
    schema = {'$ref': '#/$defs/My_Type-123'}
    result = _ref_to_def_name(schema)

def test_get_property_name_options_with_special_chars_in_enum():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options with special characters in enum values.'
    type_definition = {'properties': {'property_name': {'enum': ['size_px', 'aspect-ratio', 'width.max']}}}
    defs = {}
    result = _get_property_name_options(type_definition, defs)

def test_prepare_operations_descriptions_kind_consistency():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that Kind values in input_kind and output_kind are consistent.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_kind_consistency', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for desc in result:
        pass

def test_prepare_operations_descriptions_performance():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that prepare_operations_descriptions completes in reasonable time.'
    import time
    start_time = time.time()
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_performance', 'prepare_operations_descriptions', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    end_time = time.time()
    execution_time = end_time - start_time

def test_prepare_operations_descriptions_multiple_calls_performance():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test performance when calling prepare_operations_descriptions multiple times.'
    import time
    num_calls = 100
    start_time = time.time()
    for _ in range(num_calls):
        _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_multiple_calls_performance', 'prepare_operations_descriptions', '4_0', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
        codeflash_output = codeflash_return_value
        result = codeflash_output
    end_time = time.time()
    total_time = end_time - start_time

def test_prepare_operations_descriptions_all_descriptions_valid():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that all returned OperationDescription instances are valid Pydantic models.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_all_descriptions_valid', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for desc in result:
        desc_dict = desc.model_dump()

def test_prepare_operations_descriptions_json_serialization():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that all OperationDescription instances can be JSON serialized.'
    import json
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_json_serialization', 'prepare_operations_descriptions', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for desc in result:
        desc_dict = desc.model_dump()
        json_str = json.dumps(desc_dict)
        parsed = json.loads(json_str)

def test_prepare_operations_descriptions_large_iteration():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test iterating over results multiple times with large index access.'
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_large_iteration', 'prepare_operations_descriptions', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for _ in range(10):
        for i in range(len(result)):
            desc = result[i]

def test_prepare_operations_descriptions_field_access_performance():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that accessing all fields is performant.'
    import time
    _call__bound__arguments = inspect.signature(prepare_operations_descriptions).bind()
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(prepare_operations_descriptions, 'tests.inference.unit_tests.test_prepare_operations_descriptions__unit_test_1', None, 'test_prepare_operations_descriptions_field_access_performance', 'prepare_operations_descriptions', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    num_iterations = 1000
    start_time = time.time()
    for _ in range(num_iterations):
        for desc in result:
            _ = desc.operation_type
            _ = desc.compound
            _ = desc.input_kind
            _ = desc.output_kind
            _ = desc.nested_operation_input_kind
            _ = desc.nested_operation_output_kind
            _ = desc.property_name_options
    end_time = time.time()
    total_time = end_time - start_time

def test_get_property_name_options_with_large_enum():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options with a large enum list.'
    large_enum = [f'property_{i}' for i in range(1000)]
    type_definition = {'properties': {'property_name': {'enum': large_enum}}}
    defs = {}
    result = _get_property_name_options(type_definition, defs)

def test_ref_to_def_name_with_many_path_segments():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _ref_to_def_name with many path segments.'
    segments = ['segment'] * 100
    path = '#/' + '/'.join(segments) + '/FinalType'
    schema = {'$ref': path}
    result = _ref_to_def_name(schema)

def test_get_property_name_options_with_deep_nested_ref():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test _get_property_name_options with deeply nested reference structure.'
    type_definition = {'properties': {'property_name': {'$ref': '#/$defs/Level1'}}}
    defs = {'Level1': {'enum': [f'level1_option_{i}' for i in range(100)]}}
    result = _get_property_name_options(type_definition, defs)