feat: add unified strategy project workflow
This commit is contained in:
1 parent
67d12929fc
commit
a26fd32eba
28 files changed
+3382
-191
No files matched your search
@@ -6,9 +6,13 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.gateway.routers import _strategy_selection_seed as seed
|
||||
from app.gateway.routers import agents as agents_router
|
||||
from deerflow.config.paths import Paths
|
||||
from deerflow.persistence.skills.memory import MemorySkillStore
|
||||
from deerflow.skills.types import Skill, SkillCategory
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@@ -73,6 +77,18 @@ def test_seed_assets_use_role_appropriate_existing_skills_and_tools() -> None:
|
||||
assert solution["tool_groups"] == ["file:write"]
|
||||
|
||||
|
||||
def test_default_strategy_skills_are_enabled_in_the_system_catalog() -> None:
|
||||
extensions_path = Path(__file__).resolve().parents[1] / "extensions_config.json"
|
||||
extensions = yaml.safe_load(extensions_path.read_text(encoding="utf-8")) or {}
|
||||
configured = extensions.get("skills") or {}
|
||||
|
||||
# A missing entry means enabled by default. An explicit false would make
|
||||
# the seeded allowlist impossible to save under the server-side validator
|
||||
# and silently remove the skill from strategy runs.
|
||||
for skill_name in ("intent-clarification-policy", "policy-knowledge"):
|
||||
assert (configured.get(skill_name) or {}).get("enabled", True) is True
|
||||
|
||||
|
||||
def test_seed_assets_define_machine_readable_handoff_contracts() -> None:
|
||||
intent_soul = _asset(seed.STRATEGY_INTENT_AGENT_ID, "SOUL.md").read_text(encoding="utf-8")
|
||||
judge_soul = _asset(seed.STRATEGY_JUDGE_AGENT_ID, "SOUL.md").read_text(encoding="utf-8")
|
||||
@@ -113,3 +129,120 @@ def test_seed_creates_once_and_never_overwrites_admin_changes(tmp_paths: Paths)
|
||||
|
||||
assert seed.ensure_strategy_selection_agents() == []
|
||||
assert customized_soul.read_text(encoding="utf-8") == "管理员现场修改"
|
||||
|
||||
|
||||
class _SkillStorage:
|
||||
def __init__(self, skills: list[Skill]) -> None:
|
||||
self._skills = skills
|
||||
|
||||
def load_skills(self, *, enabled_only: bool) -> list[Skill]:
|
||||
if enabled_only:
|
||||
return [skill for skill in self._skills if skill.enabled]
|
||||
return list(self._skills)
|
||||
|
||||
|
||||
def _skill(name: str, *, category: SkillCategory, enabled: bool = True) -> Skill:
|
||||
directory = Path("skills") / category.value / name
|
||||
return Skill(
|
||||
name=name,
|
||||
description=name,
|
||||
license=None,
|
||||
skill_dir=directory,
|
||||
skill_file=directory / "SKILL.md",
|
||||
relative_path=Path(name),
|
||||
category=category,
|
||||
enabled=enabled,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_strategy_skill_validation_accepts_only_global_catalog_names(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
skill_store = MemorySkillStore()
|
||||
await skill_store.create(
|
||||
{
|
||||
"name": "published-custom",
|
||||
"owner_user_id": "publisher",
|
||||
"published": True,
|
||||
}
|
||||
)
|
||||
storage = _SkillStorage(
|
||||
[
|
||||
_skill("public-skill", category=SkillCategory.PUBLIC),
|
||||
_skill("published-custom", category=SkillCategory.CUSTOM),
|
||||
]
|
||||
)
|
||||
monkeypatch.setattr(agents_router, "get_or_new_skill_storage", lambda **_: storage)
|
||||
monkeypatch.setattr(
|
||||
agents_router,
|
||||
"get_skill_usage_entries",
|
||||
lambda: {},
|
||||
)
|
||||
|
||||
result = await agents_router._validate_strategy_agent_skills(
|
||||
[" public-skill ", "published-custom", "public-skill"],
|
||||
app_config=object(), # type: ignore[arg-type]
|
||||
skill_store=skill_store,
|
||||
)
|
||||
|
||||
assert result == ["public-skill", "published-custom"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("requested", "detail_fragment"),
|
||||
[
|
||||
("missing", "Unknown strategy agent skills"),
|
||||
("disabled", "Disabled or archived strategy agent skills"),
|
||||
("stale", "Disabled or archived strategy agent skills"),
|
||||
("private-custom", "must be globally available"),
|
||||
("orphan-custom", "must be globally available"),
|
||||
],
|
||||
)
|
||||
async def test_strategy_skill_validation_rejects_unselectable_names(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
requested: str,
|
||||
detail_fragment: str,
|
||||
) -> None:
|
||||
skill_store = MemorySkillStore()
|
||||
await skill_store.create(
|
||||
{
|
||||
"name": "private-custom",
|
||||
"owner_user_id": "owner",
|
||||
"published": False,
|
||||
}
|
||||
)
|
||||
storage = _SkillStorage(
|
||||
[
|
||||
_skill("disabled", category=SkillCategory.PUBLIC, enabled=False),
|
||||
_skill("stale", category=SkillCategory.PUBLIC),
|
||||
_skill("private-custom", category=SkillCategory.CUSTOM),
|
||||
_skill("orphan-custom", category=SkillCategory.CUSTOM),
|
||||
]
|
||||
)
|
||||
monkeypatch.setattr(agents_router, "get_or_new_skill_storage", lambda **_: storage)
|
||||
monkeypatch.setattr(
|
||||
agents_router,
|
||||
"get_skill_usage_entries",
|
||||
lambda: {"stale": {"state": "stale"}},
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await agents_router._validate_strategy_agent_skills(
|
||||
[requested],
|
||||
app_config=object(), # type: ignore[arg-type]
|
||||
skill_store=skill_store,
|
||||
)
|
||||
|
||||
assert exc_info.value.status_code == 422
|
||||
assert detail_fragment in str(exc_info.value.detail)
|
||||
|
||||
|
||||
def test_fixed_strategy_role_agents_cannot_be_deleted() -> None:
|
||||
for agent_id in seed.required_agent_ids():
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
agents_router._ensure_strategy_agent_deletable(agent_id)
|
||||
assert exc_info.value.status_code == 409
|
||||
|
||||
agents_router._ensure_strategy_agent_deletable("ordinary-custom-agent")
|
||||
Reference in new issue
Block a user