# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

"""Tests for the project's task registrations."""

import gymnasium as gym

import {{ name }}.tasks  # noqa: F401


def test_task_registrations():
    """The project tasks must expose valid environment and agent entry points."""
{% if specifications %}
    expected = {
{% for specification in specifications %}
        "{{ specification.task.id }}": {
            "entry_point": {% if specification.task.workflow.name == "direct" or specification.task.amp_selected %}"{{ name }}.tasks.{{ specification.task.family_name }}.config.{{ robot_name }}.{{ specification.task.env_filename }}:{{ specification.task.classname }}Env"{% else %}"isaaclab.envs:ManagerBasedRLEnv"{% endif %},
            "env_cfg_entry_point": "{{ name }}.tasks.{{ specification.task.family_name }}.config.{{ robot_name }}.{{ specification.task.env_cfg_filename }}:{{ specification.task.classname }}EnvCfg",
{% if specification.rl_libraries | length == 1 %}
            "default_agent": "{{ specification.rl_libraries[0].name }}",
{% endif %}
        },
{% endfor %}
    }
{% else %}
    assert all(
        not str(spec.kwargs.get("env_cfg_entry_point", "")).startswith("{{ name }}.tasks")
        for spec in gym.registry.values()
    )
{% endif %}

{% if specifications %}
    for task_id, expected_values in expected.items():
        spec = gym.spec(task_id)
        assert spec.entry_point == expected_values["entry_point"]
        assert spec.kwargs["env_cfg_entry_point"] == expected_values["env_cfg_entry_point"]
        if "default_agent" in expected_values:
            assert spec.kwargs["default_agent"] == expected_values["default_agent"]
{% endif %}
