|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +from pathlib import Path |
| 16 | +from types import SimpleNamespace |
| 17 | +from unittest import mock |
15 | 18 | from unittest.mock import patch |
16 | 19 |
|
| 20 | +from google.adk.cli import service_registry |
17 | 21 | import pytest |
18 | 22 |
|
19 | 23 |
|
@@ -124,6 +128,33 @@ def test_create_artifact_service_gcs(registry, mock_services): |
124 | 128 | ) |
125 | 129 |
|
126 | 130 |
|
| 131 | +def test_file_artifact_factory_normalizes_windows_file_uri(monkeypatch): |
| 132 | + monkeypatch.setattr(service_registry, "os", SimpleNamespace(name="nt")) |
| 133 | + mocked_url2pathname = mock.Mock(return_value=r"C:\tmp\adk artifacts") |
| 134 | + monkeypatch.setattr(service_registry, "url2pathname", mocked_url2pathname) |
| 135 | + |
| 136 | + registry = service_registry.ServiceRegistry() |
| 137 | + service_registry._register_builtin_services(registry) |
| 138 | + |
| 139 | + with mock.patch( |
| 140 | + "google.adk.artifacts.file_artifact_service.FileArtifactService" |
| 141 | + ) as mock_file_artifact_service: |
| 142 | + registry.create_artifact_service("file:///C:/tmp/adk%20artifacts") |
| 143 | + |
| 144 | + mocked_url2pathname.assert_called_once_with("/C:/tmp/adk artifacts") |
| 145 | + mock_file_artifact_service.assert_called_once_with( |
| 146 | + root_dir=Path(r"C:\tmp\adk artifacts") |
| 147 | + ) |
| 148 | + |
| 149 | + |
| 150 | +def test_file_artifact_factory_rejects_non_local_authority(): |
| 151 | + registry = service_registry.ServiceRegistry() |
| 152 | + service_registry._register_builtin_services(registry) |
| 153 | + |
| 154 | + with pytest.raises(ValueError, match="local filesystem"): |
| 155 | + registry.create_artifact_service("file://example.com/tmp/adk_artifacts") |
| 156 | + |
| 157 | + |
127 | 158 | # Memory Service Tests |
128 | 159 | @patch("google.adk.cli.utils.envs.load_dotenv_for_agent") |
129 | 160 | def test_create_memory_service_rag( |
|
0 commit comments