deer-flow/backend/tests/test_tool_documentation.py
Hoouse f9e05c24ea
docs(tutorials): add required tool names and groups (#7922)
* docs: complete tool configuration examples in tutorials

Signed-off-by: ZKDplz <2646995705@qq.com>

* test(docs): validate tutorial tool configuration examples

Signed-off-by: ZKDplz <2646995705@qq.com>

* docs: complete tool configuration examples in related guides

---------

Signed-off-by: ZKDplz <2646995705@qq.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-11-06 21:10:30 +08:00

36 lines
1.2 KiB
Python

"""Keep documented tool examples aligned with the configuration schema."""
import re
from pathlib import Path
import pytest
import yaml
from pydantic import TypeAdapter
from deerflow.config.tool_config import ToolConfig
REPO_ROOT = Path(__file__).resolve().parents[2]
TOOL_GUIDES = (
"application/configuration.mdx",
"harness/configuration.mdx",
"harness/tools.mdx",
"tutorials/create-your-first-harness.mdx",
"tutorials/use-tools-and-skills.mdx",
)
@pytest.mark.parametrize("language", ("en", "zh"))
@pytest.mark.parametrize("guide", TOOL_GUIDES)
def test_tool_examples_are_valid(language: str, guide: str) -> None:
path = REPO_ROOT / "frontend" / "src" / "content" / language / guide
content = path.read_text(encoding="utf-8")
blocks = re.findall(r"```yaml\n(.*?)\n```", content, flags=re.DOTALL)
examples = [yaml.safe_load(block) for block in blocks]
tool_examples = [example["tools"] for example in examples if isinstance(example, dict) and "tools" in example]
assert tool_examples, f"no tool configuration example in {path}"
adapter = TypeAdapter(list[ToolConfig])
for tools in tool_examples:
assert tools, f"empty tool configuration example in {path}"
adapter.validate_python(tools)