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 \
    _extract_workflow_caller_ids_from_spec


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
WORKFLOW_CALLER_BLOCK_TYPE = 'roboflow_core/workflow_caller@v1'

def test_empty_spec():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with an empty spec dictionary.'
    spec = {}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_empty_spec', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_spec_with_no_steps():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    "Test with a spec that has no 'steps' key."
    spec = {'name': 'test_workflow'}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_spec_with_no_steps', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_spec_with_empty_steps():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with a spec that has an empty steps list.'
    spec = {'steps': []}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_spec_with_empty_steps', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_valid_workflow_caller_with_version():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with a single valid workflow caller step with version.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'my_workflow_123', 'workflow_version_id': 'version_456'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_single_valid_workflow_caller_with_version', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_valid_workflow_caller_without_version():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with a single valid workflow caller step without version.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'my_workflow_123'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_single_valid_workflow_caller_without_version', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_workflow_id_is_selector_excluded():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that workflow_id starting with $ is excluded.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': '$inputs.workflow_id'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_workflow_id_is_selector_excluded', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_version_id_is_selector_converted_to_none():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that workflow_version_id starting with $ is converted to None.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'my_workflow_123', 'workflow_version_id': '$inputs.version_id'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_version_id_is_selector_converted_to_none', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_wrong_step_type_excluded():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that steps with wrong type are excluded.'
    spec = {'steps': [{'type': 'roboflow_core/model_run@v1', 'workflow_id': 'my_workflow_123'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_wrong_step_type_excluded', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_multiple_valid_steps():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with multiple valid workflow caller steps.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_1', 'workflow_version_id': 'v1'}, {'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_2', 'workflow_version_id': 'v2'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_multiple_valid_steps', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_mixed_valid_and_invalid_steps():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with a mix of valid and invalid steps.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_1', 'workflow_version_id': 'v1'}, {'type': 'roboflow_core/model_run@v1', 'workflow_id': 'workflow_2'}, {'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': '$dynamic_id'}, {'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_3'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_mixed_valid_and_invalid_steps', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_workflow_id_is_not_string_excluded():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that non-string workflow_id is excluded.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 12345}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_workflow_id_is_not_string_excluded', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_version_id_is_not_string_preserved():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that non-string version_id is preserved as-is (not None).'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_1', 'workflow_version_id': 12345}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_version_id_is_not_string_preserved', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_empty_workflow_id_string():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with an empty workflow_id string.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': ''}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_empty_workflow_id_string', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_workflow_id_with_special_characters():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with special characters in workflow_id.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow-123_abc.test'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_workflow_id_with_special_characters', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_version_id_with_special_characters():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with special characters in version_id.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_1', 'workflow_version_id': 'v1.2.3-beta+build.456'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_version_id_with_special_characters', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_step_missing_type():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    "Test with a step missing the 'type' field."
    spec = {'steps': [{'workflow_id': 'workflow_1'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_step_missing_type', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_step_missing_workflow_id():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    "Test with a step missing the 'workflow_id' field."
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_step_missing_workflow_id', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_workflow_id_exactly_dollar_sign():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with workflow_id being exactly a dollar sign.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': '$'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_workflow_id_exactly_dollar_sign', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_version_id_exactly_dollar_sign():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with version_id being exactly a dollar sign.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_1', 'workflow_version_id': '$'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_version_id_exactly_dollar_sign', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_case_sensitive_type_matching():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that type matching is case-sensitive.'
    spec = {'steps': [{'type': 'ROBOFLOW_CORE/WORKFLOW_CALLER@V1', 'workflow_id': 'workflow_1'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_case_sensitive_type_matching', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_workflow_id_with_unicode_characters():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with Unicode characters in workflow_id.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_日本語_test'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_workflow_id_with_unicode_characters', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_nested_dict_in_step():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with nested structures in step (should not affect extraction).'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_1', 'workflow_version_id': 'v1', 'nested': {'config': 'value'}, 'extra_field': [1, 2, 3]}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_nested_dict_in_step', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_version_id_is_none():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with version_id explicitly set to None.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_1', 'workflow_version_id': None}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_version_id_is_none', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_version_id_is_boolean():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with version_id being a boolean value.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': 'workflow_1', 'workflow_version_id': True}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_version_id_is_boolean', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_workflow_id_with_leading_dollar_variations():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test various selector patterns starting with $.'
    spec = {'steps': [{'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': '$inputs.wf_id'}, {'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': '$env.workflow_name'}, {'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': '$steps.step1.output'}]}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_workflow_id_with_leading_dollar_variations', '_extract_workflow_caller_ids_from_spec', '2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_number_of_valid_steps():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with a large number of valid workflow caller steps.'
    steps = []
    for i in range(1000):
        steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': f'workflow_{i}', 'workflow_version_id': f'v_{i}'})
    spec = {'steps': steps}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_large_number_of_valid_steps', '_extract_workflow_caller_ids_from_spec', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i, (wf_id, v_id) in enumerate(result):
        pass

def test_large_number_of_mixed_step_types():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with many steps of different types.'
    steps = []
    step_types = ['roboflow_core/workflow_caller@v1', 'roboflow_core/model_run@v1', 'roboflow_core/classifier@v1', 'roboflow_core/detector@v1']
    for i in range(1000):
        step_type = step_types[i % len(step_types)]
        steps.append({'type': step_type, 'workflow_id': f'workflow_{i}', 'workflow_version_id': f'v_{i}'})
    spec = {'steps': steps}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_large_number_of_mixed_step_types', '_extract_workflow_caller_ids_from_spec', '5', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for wf_id, v_id in result:
        pass

def test_large_number_of_selector_steps():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with many steps where workflow_id is a selector.'
    steps = []
    for i in range(1000):
        steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': f'$input_{i}', 'workflow_version_id': f'v_{i}'})
    spec = {'steps': steps}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_large_number_of_selector_steps', '_extract_workflow_caller_ids_from_spec', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_number_of_mixed_valid_and_selector():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with alternating valid and selector workflow_ids.'
    steps = []
    for i in range(1000):
        if i % 2 == 0:
            workflow_id = f'workflow_{i}'
        else:
            workflow_id = f'$selector_{i}'
        steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': workflow_id, 'workflow_version_id': f'v_{i}'})
    spec = {'steps': steps}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_large_number_of_mixed_valid_and_selector', '_extract_workflow_caller_ids_from_spec', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for idx, (wf_id, v_id) in enumerate(result):
        expected_i = idx * 2

def test_large_spec_with_very_long_workflow_ids():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with large spec containing very long workflow_id strings.'
    steps = []
    for i in range(100):
        long_id = 'w' * 10000 + str(i)
        steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': long_id, 'workflow_version_id': f'v_{i}'})
    spec = {'steps': steps}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_large_spec_with_very_long_workflow_ids', '_extract_workflow_caller_ids_from_spec', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for idx, (wf_id, v_id) in enumerate(result):
        pass

def test_large_spec_with_many_missing_fields():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test performance with many steps missing optional fields.'
    steps = []
    for i in range(1000):
        step = {'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': f'workflow_{i}'}
        if i % 2 == 0:
            step['workflow_version_id'] = f'v_{i}'
        steps.append(step)
    spec = {'steps': steps}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_large_spec_with_many_missing_fields', '_extract_workflow_caller_ids_from_spec', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i, (wf_id, v_id) in enumerate(result):
        if i % 2 == 0:
            pass
        else:
            pass

def test_stress_test_with_mixed_data_types():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Stress test with mixed data types for all fields.'
    steps = []
    for i in range(500):
        if i % 5 == 0:
            steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': f'workflow_{i}', 'workflow_version_id': f'v_{i}'})
        elif i % 5 == 1:
            steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': i, 'workflow_version_id': f'v_{i}'})
        elif i % 5 == 2:
            steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': f'workflow_{i}', 'workflow_version_id': i})
        elif i % 5 == 3:
            steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': f'$selector_{i}', 'workflow_version_id': f'v_{i}'})
        else:
            steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': f'workflow_{i}', 'workflow_version_id': f'$selector_{i}'})
    spec = {'steps': steps}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_stress_test_with_mixed_data_types', '_extract_workflow_caller_ids_from_spec', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    valid_indices = [i for i in range(500) if i % 5 in [0, 2, 4]]
    for idx, (wf_id, v_id) in enumerate(result):
        actual_i = valid_indices[idx]

def test_performance_with_deeply_nested_spec():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test performance when spec has extra nested fields.'
    steps = []
    for i in range(500):
        steps.append({'type': 'roboflow_core/workflow_caller@v1', 'workflow_id': f'workflow_{i}', 'workflow_version_id': f'v_{i}', 'config': {'nested': {'deep': {'structure': {'value': i}}}}, 'metadata': [1, 2, 3, 4, 5] * 10, 'tags': {f'tag_{j}': f'value_{j}' for j in range(20)}})
    spec = {'steps': steps, 'global_config': {'key': 'value'}}
    _call__bound__arguments = inspect.signature(_extract_workflow_caller_ids_from_spec).bind(spec)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(_extract_workflow_caller_ids_from_spec, 'tests.inference.unit_tests.test__extract_workflow_caller_ids_from_spec__unit_test_1', None, 'test_performance_with_deeply_nested_spec', '_extract_workflow_caller_ids_from_spec', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i, (wf_id, v_id) in enumerate(result):
        pass