"""Tests for save_scene tool."""

import pytest
from unittest.mock import AsyncMock, patch

from godotiq.tools.bridge.save_scene import save_scene


class TestSaveSceneTool:
    @pytest.mark.asyncio
    async def test_save_in_place(self):
        """Save should call bridge with empty params."""
        mock_bridge = AsyncMock()
        mock_bridge.request = AsyncMock(return_value={
            "saved": True,
            "scene_path": "res://scenes/main.tscn",
            "scene_name": "Main",
        })
        with patch("godotiq.tools.bridge.save_scene.get_bridge", return_value=mock_bridge):
            result = await save_scene()
            assert result["saved"] is True
            assert result["scene_path"] == "res://scenes/main.tscn"
            call_args = mock_bridge.request.call_args
            assert call_args[0][0] == "save_scene"
            params = call_args[1].get("params", {})
            assert params == {}

    @pytest.mark.asyncio
    async def test_timeout_value(self):
        """Save should use 5.0s timeout."""
        mock_bridge = AsyncMock()
        mock_bridge.request = AsyncMock(return_value={"saved": True})
        with patch("godotiq.tools.bridge.save_scene.get_bridge", return_value=mock_bridge):
            await save_scene()
            call_args = mock_bridge.request.call_args
            timeout = call_args[1].get("timeout")
            assert timeout == 5.0

    @pytest.mark.asyncio
    async def test_bridge_exception_propagates(self):
        """Bridge exceptions should propagate (handled by registration layer)."""
        mock_bridge = AsyncMock()
        mock_bridge.request = AsyncMock(side_effect=Exception("NO_SCENE"))
        with patch("godotiq.tools.bridge.save_scene.get_bridge", return_value=mock_bridge):
            with pytest.raises(Exception, match="NO_SCENE"):
                await save_scene()
