import json
import unittest

from tools.task_progress import TaskProgressTool


class TaskProgressToolTests(unittest.TestCase):
    def test_schema_exposes_set_update_and_clear_actions(self) -> None:
        schema = TaskProgressTool().schema

        fn = schema["function"]
        self.assertEqual(fn["name"], "task_progress")
        action_enum = fn["parameters"]["properties"]["action"]["enum"]
        self.assertEqual(action_enum, ["set_plan", "update_step", "clear"])

    def test_execute_returns_short_ui_only_result(self) -> None:
        out = TaskProgressTool().execute(
            action="set_plan",
            steps=[
                {"id": "s1", "title": "理解需求", "status": "completed"},
                {"id": "s2", "title": "实现功能", "status": "in_progress"},
            ],
        )

        data = json.loads(out)
        self.assertEqual(data, {"ok": True, "action": "set_plan", "step_count": 2})
        self.assertLess(len(out), 80)

    def test_execute_normalizes_update_step_without_echoing_title(self) -> None:
        out = TaskProgressTool().execute(
            action="update_step",
            step={"id": "s2", "title": "实现功能", "status": "completed"},
        )

        data = json.loads(out)
        self.assertEqual(data, {"ok": True, "action": "update_step", "step_id": "s2"})
        self.assertNotIn("实现功能", out)


if __name__ == "__main__":
    unittest.main()
