"""
测试 tool_schemas.py —— FINALIZE_TASK_SCHEMA / RUN_SKILLS_SCHEMA 定义和注册
"""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent))

from aacode.utils.tool_schemas import (
    FINALIZE_TASK_SCHEMA,
    RUN_SKILLS_SCHEMA,
    get_all_schemas,
)


class TestToolSchemas:
    """新增 schema 验证"""

    def test_finalize_task_schema(self):
        assert FINALIZE_TASK_SCHEMA.name == "finalize_task"
        assert len(FINALIZE_TASK_SCHEMA.parameters) == 0
        assert FINALIZE_TASK_SCHEMA.examples == []

    def test_run_skills_schema(self):
        assert RUN_SKILLS_SCHEMA.name == "run_skills"
        assert len(RUN_SKILLS_SCHEMA.parameters) == 2
        names = {p.name for p in RUN_SKILLS_SCHEMA.parameters}
        assert names == {"skill_name", "params"}
        required = {p.name for p in RUN_SKILLS_SCHEMA.parameters if p.required}
        assert "skill_name" not in required  # 可选，fallback from params

    def test_all_schemas_contains_core_tools(self):
        static = get_all_schemas()
        assert "run_shell" in static
        assert "finalize_task" in static
        assert "run_skills" in static

    def test_old_tools_not_in_all_schemas(self):
        static = get_all_schemas()
        assert "list_skills" not in static
        assert "get_skill_info" not in static
        assert "run_skill" not in static

    def test_get_all_schemas_returns_static_only(self):
        static = get_all_schemas()
        # run_skills is the only skill tool
        assert "run_skills" in static
        # no per-function skill tools
        skill_tools = [n for n in static if n.startswith(("pandas_", "numpy_", "playwright_"))]
        assert len(skill_tools) == 0
