<?php

use Illuminate\Support\Str;

it('does not use ad-hoc sleep/usleep retry loops in bulk worker jobs', function () {
    $root = base_path('app/Jobs/Operations');

    $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root));

    $paths = collect(iterator_to_array($iterator))
        ->filter(fn (\SplFileInfo $file): bool => $file->isFile() && $file->getExtension() === 'php')
        ->map(fn (\SplFileInfo $file): string => $file->getPathname())
        ->values();

    expect($paths)->not->toBeEmpty();

    $violations = [];

    foreach ($paths as $path) {
        $contents = file_get_contents($path);

        if ($contents === false) {
            continue;
        }

        if (Str::contains($contents, ['sleep(', 'usleep('])) {
            $violations[] = $path;
        }
    }

    expect($violations)->toBe([]);
});
