from __future__ import annotations

import gc
import inspect
import os
import time
from datetime import datetime, timedelta
from pathlib import Path
from typing import List

import dill as pickle
import pytest
from inference.core.managers.inference_models_cache_watchdog import (
    FileInfo, rank_for_deletion)


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

class StalenessGroup:
    """Enum-like class for staleness categories."""
    RECENT = 0
    WARM = 1
    STALE = 2
    ABANDONED = 3
SECONDS_IN_DAY = 60 * 60 * 24
RECENT_THRESHOLD_DAYS = 1
WARM_THRESHOLD_DAYS = 7
STALE_THRESHOLD_DAYS = 30

def test_empty_file_list():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that an empty file list returns an empty list.'
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([])
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_empty_file_list', 'rank_for_deletion', '1', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_recent_file():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking a single recent file (less than 1 day old).'
    now = datetime.now()
    recent_file = FileInfo('recent.txt', now - timedelta(hours=12), 10.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([recent_file], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_single_recent_file', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_warm_file():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking a single warm file (1-7 days old).'
    now = datetime.now()
    warm_file = FileInfo('warm.txt', now - timedelta(days=3), 20.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([warm_file], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_single_warm_file', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_stale_file():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking a single stale file (7-30 days old).'
    now = datetime.now()
    stale_file = FileInfo('stale.txt', now - timedelta(days=15), 30.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([stale_file], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_single_stale_file', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_single_abandoned_file():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking a single abandoned file (more than 30 days old).'
    now = datetime.now()
    abandoned_file = FileInfo('abandoned.txt', now - timedelta(days=60), 40.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([abandoned_file], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_single_abandoned_file', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_multiple_files_all_recent():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking multiple files all in the recent category.'
    now = datetime.now()
    files = [FileInfo('file1.txt', now - timedelta(hours=6), 10.0), FileInfo('file2.txt', now - timedelta(hours=12), 5.0), FileInfo('file3.txt', now - timedelta(hours=23), 15.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_multiple_files_all_recent', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_multiple_files_mixed_categories():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking files from different staleness categories.'
    now = datetime.now()
    files = [FileInfo('recent.txt', now - timedelta(hours=12), 10.0), FileInfo('warm.txt', now - timedelta(days=4), 20.0), FileInfo('stale.txt', now - timedelta(days=20), 30.0), FileInfo('abandoned.txt', now - timedelta(days=50), 40.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_multiple_files_mixed_categories', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_files_sorted_by_size_within_category():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that files within the same category are sorted by size (descending).'
    now = datetime.now()
    files = [FileInfo('small_recent.txt', now - timedelta(hours=6), 5.0), FileInfo('large_recent.txt', now - timedelta(hours=12), 20.0), FileInfo('medium_recent.txt', now - timedelta(hours=18), 15.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_files_sorted_by_size_within_category', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_uses_default_now_when_not_provided():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that datetime.now() is used when now parameter is not provided.'
    now_time = datetime.now()
    files = [FileInfo('file.txt', now_time - timedelta(hours=12), 10.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_uses_default_now_when_not_provided', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_custom_thresholds():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking with custom threshold values.'
    now = datetime.now()
    files = [FileInfo('file1.txt', now - timedelta(days=2), 10.0), FileInfo('file2.txt', now - timedelta(days=8), 20.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now, recent_threshold_days=0.5, warm_threshold_days=3, stale_threshold_days=10)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_custom_thresholds', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_file_exactly_at_recent_threshold():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test file age exactly at the recent threshold boundary.'
    now = datetime.now()
    file_at_threshold = FileInfo('boundary.txt', now - timedelta(days=1, seconds=0), 10.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([file_at_threshold], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_file_exactly_at_recent_threshold', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_file_just_below_recent_threshold():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test file age just below the recent threshold boundary.'
    now = datetime.now()
    file_below_threshold = FileInfo('below.txt', now - timedelta(days=0.999), 10.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([file_below_threshold], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_file_just_below_recent_threshold', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_file_just_above_warm_threshold():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test file age just above the warm threshold boundary.'
    now = datetime.now()
    file_above_warm = FileInfo('above_warm.txt', now - timedelta(days=7.001), 10.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([file_above_warm], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_file_just_above_warm_threshold', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_file_exactly_at_stale_threshold():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test file age exactly at the stale threshold boundary.'
    now = datetime.now()
    file_at_stale = FileInfo('at_stale.txt', now - timedelta(days=30, seconds=0), 10.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([file_at_stale], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_file_exactly_at_stale_threshold', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_file_with_zero_size():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking files with zero size.'
    now = datetime.now()
    zero_size_file = FileInfo('empty.txt', now - timedelta(hours=6), 0.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([zero_size_file], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_file_with_zero_size', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_file_with_large_size():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking files with very large size values.'
    now = datetime.now()
    large_file = FileInfo('huge.iso', now - timedelta(hours=6), 999999.99)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([large_file], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_file_with_large_size', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_thresholds_not_in_ascending_order_raises_error():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that ValueError is raised when thresholds are not in ascending order.'
    now = datetime.now()
    files = [FileInfo('file.txt', now - timedelta(hours=1), 10.0)]
    with pytest.raises(ValueError, match='Thresholds must be in ascending order'):
        _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now, recent_threshold_days=7, warm_threshold_days=7)
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_thresholds_not_in_ascending_order_raises_error', 'rank_for_deletion', '3_0', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)

def test_thresholds_equal_raises_error():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that ValueError is raised when all thresholds are equal.'
    now = datetime.now()
    files = [FileInfo('file.txt', now - timedelta(hours=1), 10.0)]
    with pytest.raises(ValueError, match='Thresholds must be in ascending order'):
        _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now, recent_threshold_days=5, warm_threshold_days=5, stale_threshold_days=5)
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_thresholds_equal_raises_error', 'rank_for_deletion', '3_0', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)

def test_thresholds_reversed_order_raises_error():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that ValueError is raised when thresholds are in reversed order.'
    now = datetime.now()
    files = [FileInfo('file.txt', now - timedelta(hours=1), 10.0)]
    with pytest.raises(ValueError, match='Thresholds must be in ascending order'):
        _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now, recent_threshold_days=30, warm_threshold_days=7, stale_threshold_days=1)
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_thresholds_reversed_order_raises_error', 'rank_for_deletion', '3_0', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)

def test_very_small_threshold_differences():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with very small differences between thresholds.'
    now = datetime.now()
    files = [FileInfo('file1.txt', now - timedelta(hours=1), 10.0), FileInfo('file2.txt', now - timedelta(hours=2), 20.0), FileInfo('file3.txt', now - timedelta(hours=3), 30.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now, recent_threshold_days=0.001, warm_threshold_days=0.002, stale_threshold_days=0.003)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_very_small_threshold_differences', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_files_modified_in_future():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test behavior when file modification time is in the future.'
    now = datetime.now()
    future_file = FileInfo('future.txt', now + timedelta(days=1), 10.0)
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind([future_file], now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_files_modified_in_future', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_multiple_files_same_size_same_age():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking files with identical size and age.'
    now = datetime.now()
    files = [FileInfo('file1.txt', now - timedelta(days=2), 10.0), FileInfo('file2.txt', now - timedelta(days=2), 10.0), FileInfo('file3.txt', now - timedelta(days=2), 10.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_multiple_files_same_size_same_age', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_extreme_threshold_values():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with extreme but valid threshold values.'
    now = datetime.now()
    files = [FileInfo('file.txt', now - timedelta(days=100), 10.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now, recent_threshold_days=0.0001, warm_threshold_days=0.0002, stale_threshold_days=10000)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_extreme_threshold_values', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_float_threshold_values():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that threshold values can be floats.'
    now = datetime.now()
    files = [FileInfo('file1.txt', now - timedelta(hours=12), 10.0), FileInfo('file2.txt', now - timedelta(days=3), 20.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now, recent_threshold_days=0.5, warm_threshold_days=5.5, stale_threshold_days=10.5)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_float_threshold_values', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_files_special_characters_in_name():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking files with special characters in name.'
    now = datetime.now()
    files = [FileInfo('file@#$.txt', now - timedelta(hours=6), 10.0), FileInfo('file-with-dashes.txt', now - timedelta(hours=12), 20.0), FileInfo('file_with_underscores.txt', now - timedelta(hours=18), 15.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_files_special_characters_in_name', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_negative_size_values():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking files with negative size values (edge case).'
    now = datetime.now()
    files = [FileInfo('negative.txt', now - timedelta(hours=6), -10.0), FileInfo('positive.txt', now - timedelta(hours=6), 10.0)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_negative_size_values', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_number_of_files_all_recent():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking 1000 recent files.'
    now = datetime.now()
    files = [FileInfo(f'file_{i}.txt', now - timedelta(hours=i % 24), float(i)) for i in range(1000)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_large_number_of_files_all_recent', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_number_of_files_all_staleness_groups():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking 1000 files distributed across all staleness groups.'
    now = datetime.now()
    files = []
    for i in range(250):
        files.append(FileInfo(f'recent_{i}.txt', now - timedelta(hours=12 + i % 12), float(i)))
    for i in range(250):
        files.append(FileInfo(f'warm_{i}.txt', now - timedelta(days=3 + i % 4), float(i + 250)))
    for i in range(250):
        files.append(FileInfo(f'stale_{i}.txt', now - timedelta(days=15 + i % 15), float(i + 500)))
    for i in range(250):
        files.append(FileInfo(f'abandoned_{i}.txt', now - timedelta(days=50 + i % 50), float(i + 750)))
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_large_number_of_files_all_staleness_groups', 'rank_for_deletion', '7', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    recent_count = sum((1 for f in result if f.name.startswith('recent_')))
    warm_count = sum((1 for f in result if f.name.startswith('warm_')))
    stale_count = sum((1 for f in result if f.name.startswith('stale_')))
    abandoned_count = sum((1 for f in result if f.name.startswith('abandoned_')))
    recent_indices = [i for i, f in enumerate(result) if f.name.startswith('recent_')]
    warm_indices = [i for i, f in enumerate(result) if f.name.startswith('warm_')]
    if recent_indices and warm_indices:
        pass
    if warm_indices and stale_count > 0:
        stale_indices = [i for i, f in enumerate(result) if f.name.startswith('stale_')]

def test_large_number_of_files_same_age_size_variation():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking 1000 files all with same age but different sizes.'
    now = datetime.now()
    files = [FileInfo(f'file_{i}.txt', now - timedelta(days=5), float(i)) for i in range(1000)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_large_number_of_files_same_age_size_variation', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i in range(999):
        pass

def test_large_number_of_files_identical_metadata():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking 1000 files with identical metadata.'
    now = datetime.now()
    modification_time = now - timedelta(days=2)
    files = [FileInfo(f'file_{i}.txt', modification_time, 50.0) for i in range(1000)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_large_number_of_files_identical_metadata', 'rank_for_deletion', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_file_list_performance():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that ranking 1000 files completes in reasonable time.'
    import time
    now = datetime.now()
    files = [FileInfo(f'file_{i}.txt', now - timedelta(days=i % 50), float(i % 1000)) for i in range(1000)]
    start_time = time.time()
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_large_file_list_performance', 'rank_for_deletion', '5', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    elapsed_time = time.time() - start_time

def test_custom_thresholds_with_large_file_set():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test custom thresholds on a large file set.'
    now = datetime.now()
    files = [FileInfo(f'file_{i}.txt', now - timedelta(days=i % 100), float(i)) for i in range(500)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now, recent_threshold_days=10, warm_threshold_days=30, stale_threshold_days=60)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_custom_thresholds_with_large_file_set', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_files_with_very_precise_timestamps():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking files with microsecond precision in timestamps.'
    now = datetime.now()
    files = [FileInfo(f'file_{i}.txt', now - timedelta(days=5, microseconds=i), float(i)) for i in range(100)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_files_with_very_precise_timestamps', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output

def test_large_range_of_file_sizes():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test ranking files with sizes spanning many orders of magnitude.'
    now = datetime.now()
    files = [FileInfo(f'file_{i}.txt', now - timedelta(days=2), 0.001 * 2 ** i) for i in range(20)]
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_large_range_of_file_sizes', 'rank_for_deletion', '3', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output
    for i in range(19):
        pass

def test_rapid_threshold_boundary_transitions():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test many files near staleness group boundaries.'
    now = datetime.now()
    files = []
    boundary_times = [(now - timedelta(days=1.0001), 'warm_start'), (now - timedelta(days=0.9999), 'recent_end'), (now - timedelta(days=7.0001), 'stale_start'), (now - timedelta(days=6.9999), 'warm_end'), (now - timedelta(days=30.0001), 'abandoned_start'), (now - timedelta(days=29.9999), 'stale_end')]
    for j in range(50):
        for time_delta, name in boundary_times:
            files.append(FileInfo(f'{name}_{j}.txt', time_delta, float(j)))
    _call__bound__arguments = inspect.signature(rank_for_deletion).bind(files, now=now)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(rank_for_deletion, 'tests.inference.unit_tests.test_rank_for_deletion__unit_test_1', None, 'test_rapid_threshold_boundary_transitions', 'rank_for_deletion', '5', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    result = codeflash_output