feat(agent): add tool registry domain validation
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def validate_tool_spec(spec: dict[str, Any]) -> None:
|
||||
name = spec["name"]
|
||||
target = spec["execution_target"]
|
||||
if name.startswith("ui.") and target != "frontend":
|
||||
raise ValueError("ui.* must use frontend target")
|
||||
if name.startswith("srv.") and target != "backend":
|
||||
raise ValueError("srv.* must use backend target")
|
||||
@@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
|
||||
from v1.agent.tool_registry import validate_tool_spec
|
||||
|
||||
|
||||
class TestValidateToolSpec:
|
||||
def test_ui_namespace_must_be_frontend(self):
|
||||
with pytest.raises(ValueError, match="ui.* must use frontend target"):
|
||||
validate_tool_spec(
|
||||
{"name": "ui.navigate_to", "execution_target": "backend"}
|
||||
)
|
||||
|
||||
def test_srv_namespace_must_be_backend(self):
|
||||
with pytest.raises(ValueError, match="srv.* must use backend target"):
|
||||
validate_tool_spec(
|
||||
{"name": "srv.search_docs", "execution_target": "frontend"}
|
||||
)
|
||||
|
||||
def test_ui_namespace_with_frontend_is_valid(self):
|
||||
validate_tool_spec({"name": "ui.navigate_to", "execution_target": "frontend"})
|
||||
|
||||
def test_srv_namespace_with_backend_is_valid(self):
|
||||
validate_tool_spec({"name": "srv.search_docs", "execution_target": "backend"})
|
||||
|
||||
def test_other_namespace_is_valid(self):
|
||||
validate_tool_spec({"name": "other.tool", "execution_target": "frontend"})
|
||||
validate_tool_spec({"name": "other.tool", "execution_target": "backend"})
|
||||
Reference in New Issue
Block a user