#!/usr/bin/env bash
# Find the plugin file for a test.
# Usage: plugin-for-test _tests/src/infrastructure/test_url_utils.rb

set -euo pipefail
source "$(dirname "${BASH_SOURCE[0]}")/lib/common.sh"

if [[ $# -eq 0 ]]; then
    echo "Usage: $(basename "$0") <test-path>" >&2
    echo "Example: $(basename "$0") _tests/src/infrastructure/test_url_utils.rb" >&2
    exit 1
fi

test_path="${1#./}"

if [[ ! "$test_path" =~ ^$TESTS_DIR/ ]]; then
    echo "Error: Path must be under $TESTS_DIR/" >&2
    exit 1
fi

if result=$(find_plugin_for_test "$test_path"); then
    echo "$result"
else
    echo "ORPHAN"
    exit 1
fi
