import os
import re


def resolve_env_vars(env_dict: dict[str, str]) -> dict[str, str]:
    """
    Resolve environment variable templates in a dictionary.

    Templates like "${VAR_NAME}" are replaced with values from os.environ.
    Literal values are passed through unchanged.

    Args:
        env_dict: Dictionary with potentially templated values

    Returns:
        Dictionary with resolved values

    Raises:
        ValueError: If a required environment variable is not found
    """
    resolved = {}
    pattern = re.compile(r"\$\{([^}]+)\}")

    for key, value in env_dict.items():
        match = pattern.fullmatch(value)
        if match:
            # Template substitution
            var_name = match.group(1)
            if var_name not in os.environ:
                raise ValueError(
                    f"Environment variable '{var_name}' referenced in verifier.env "
                    f"but not found in host environment"
                )
            resolved[key] = os.environ[var_name]
        else:
            # Literal value
            resolved[key] = value

    return resolved
