feat: Refactor tool management and update documentation for clarity

This commit is contained in:
2026-02-21 00:29:48 -08:00
parent 08c6f3fa83
commit 54ba2ccc62
17 changed files with 160 additions and 154 deletions

View File

@@ -38,7 +38,6 @@ def castle_root(tmp_path: Path) -> Generator[Path, None, None]:
"description": "Test tool",
"install": {"path": {"alias": "test-tool"}},
"tool": {
"category": "document",
"source": "tools/document",
"system_dependencies": ["pandoc"],
},
@@ -46,9 +45,8 @@ def castle_root(tmp_path: Path) -> Generator[Path, None, None]:
"test-tool-2": {
"description": "Another test tool",
"tool": {
"category": "utility",
"source": "tools/utility",
"version": "2.0.0",
"tool_type": "script",
},
},
},

View File

@@ -9,7 +9,7 @@ class TestToolsList:
"""GET /tools endpoint tests."""
def test_returns_grouped_tools(self, client: TestClient) -> None:
"""Returns tools grouped by category."""
"""Returns tools grouped by source directory name."""
response = client.get("/tools")
assert response.status_code == 200
data = response.json()
@@ -17,8 +17,8 @@ class TestToolsList:
assert "document" in names
assert "utility" in names
def test_categories_sorted(self, client: TestClient) -> None:
"""Categories are sorted alphabetically."""
def test_groups_sorted(self, client: TestClient) -> None:
"""Groups are sorted alphabetically."""
response = client.get("/tools")
data = response.json()
names = [cat["name"] for cat in data]
@@ -28,27 +28,29 @@ class TestToolsList:
"""Tool summary has expected fields."""
response = client.get("/tools")
data = response.json()
doc_cat = next(c for c in data if c["name"] == "document")
tool = next(t for t in doc_cat["tools"] if t["id"] == "test-tool")
doc_group = next(c for c in data if c["name"] == "document")
tool = next(t for t in doc_group["tools"] if t["id"] == "test-tool")
assert tool["description"] == "Test tool"
assert tool["category"] == "document"
assert tool["source"] == "tools/document"
assert tool["system_dependencies"] == ["pandoc"]
# tool_type and category should not be present
assert "tool_type" not in tool
assert "category" not in tool
def test_installed_flag(self, client: TestClient) -> None:
"""Tool with install.path is marked as installed."""
response = client.get("/tools")
data = response.json()
doc_cat = next(c for c in data if c["name"] == "document")
tool = next(t for t in doc_cat["tools"] if t["id"] == "test-tool")
doc_group = next(c for c in data if c["name"] == "document")
tool = next(t for t in doc_group["tools"] if t["id"] == "test-tool")
assert tool["installed"] is True
def test_not_installed_flag(self, client: TestClient) -> None:
"""Tool without install.path is not marked as installed."""
response = client.get("/tools")
data = response.json()
util_cat = next(c for c in data if c["name"] == "utility")
tool = next(t for t in util_cat["tools"] if t["id"] == "test-tool-2")
util_group = next(c for c in data if c["name"] == "utility")
tool = next(t for t in util_group["tools"] if t["id"] == "test-tool-2")
assert tool["installed"] is False
def test_service_excluded(self, client: TestClient) -> None:
@@ -68,12 +70,12 @@ class TestToolDetail:
assert response.status_code == 200
data = response.json()
assert data["id"] == "test-tool"
assert data["category"] == "document"
assert data["source"] == "tools/document"
assert data["system_dependencies"] == ["pandoc"]
def test_docs_from_file(self, client: TestClient, castle_root: Path) -> None:
"""Reads documentation from .md file."""
# Create doc file matching the source lookup
# Create doc file matching the source lookup (src/<dir_name>/<tool>.md)
doc_dir = castle_root / "tools" / "document" / "src" / "document"
doc_dir.mkdir(parents=True)
(doc_dir / "test_tool.md").write_text(