Increment 5 of .scratch/solution-architect-agent/spec.md, test-first. - agents/*.md: provider-neutral role files for the Orchestrator, nine Specialists and the pillar advisor, with a shared Specialist protocol. - app/agents/roles.py: load and validate role files; Skills, MCP servers and models come from the provider bundle. - app/agents/adk_runtime.py: AgentRuntime on google-adk 2.9 with a per-run LlmAgent, role-scoped SkillToolset (no run_skill_script), step budgets, early stop on turn-ending tools, LiteLLM models. - app/execution/pillars.py + toolkit.py: design advisor fans out to one advisor per WAF pillar in parallel. - Specialists receive every earlier-Phase Deliverable as input. - Bundle gains role_skills, pillar_skills and -latest Gemini aliases; pin google-adk[extensions]==2.9.0. - 37 new tests; full suite 158 passed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
180 lines
5.8 KiB
Python
180 lines
5.8 KiB
Python
"""Cloud provider bundle loading and validation."""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
from app.providers import ProviderConfigError, load_provider
|
|
|
|
REPO_ROOT = Path(__file__).parents[1]
|
|
|
|
|
|
def test_gcp_bundle_loads_vendored_skills_and_template():
|
|
bundle = load_provider("gcp")
|
|
|
|
assert bundle.name == "gcp"
|
|
assert "google-cloud-solution-architecture" in bundle.skills
|
|
assert {name for name in bundle.skills if name.startswith("google-cloud-waf-")} == {
|
|
"google-cloud-waf-security",
|
|
"google-cloud-waf-reliability",
|
|
"google-cloud-waf-cost-optimization",
|
|
"google-cloud-waf-operational-excellence",
|
|
"google-cloud-waf-performance-optimization",
|
|
"google-cloud-waf-sustainability",
|
|
}
|
|
assert bundle.output_template == (
|
|
REPO_ROOT
|
|
/ "skills/vendor/google/google-cloud-solution-architecture/assets/output-template.md"
|
|
)
|
|
assert bundle.models.default
|
|
|
|
|
|
def test_gcp_bundle_mcp_servers_are_tiered_and_referenced_consistently():
|
|
bundle = load_provider("gcp")
|
|
|
|
general = {
|
|
server.id for server in bundle.mcp_servers.values() if server.tier == "general"
|
|
}
|
|
assert general == {"developer_knowledge"}
|
|
assert all(
|
|
server.url.startswith("https://") for server in bundle.mcp_servers.values()
|
|
)
|
|
for role, server_ids in bundle.role_mcp_servers.items():
|
|
assert set(server_ids) <= set(bundle.mcp_servers), role
|
|
|
|
|
|
def test_role_mcp_servers_can_exclude_preview_servers():
|
|
bundle = load_provider("gcp")
|
|
|
|
with_preview = {s.id for s in bundle.mcp_servers_for_role("requirements-analyst")}
|
|
without_preview = {
|
|
s.id
|
|
for s in bundle.mcp_servers_for_role(
|
|
"requirements-analyst", include_preview=False
|
|
)
|
|
}
|
|
|
|
assert "asset_inventory" in with_preview
|
|
assert "asset_inventory" not in without_preview
|
|
assert bundle.mcp_servers_for_role("no-such-role") == ()
|
|
|
|
|
|
def test_gcp_bundle_maps_roles_and_pillars_to_vendored_skills():
|
|
bundle = load_provider("gcp")
|
|
|
|
assert bundle.role_skills["orchestrator"] == ("google-cloud-solution-architecture",)
|
|
assert bundle.pillar_skills == {
|
|
"security": "google-cloud-waf-security",
|
|
"reliability": "google-cloud-waf-reliability",
|
|
"operational-excellence": "google-cloud-waf-operational-excellence",
|
|
"cost-optimization": "google-cloud-waf-cost-optimization",
|
|
"performance-optimization": "google-cloud-waf-performance-optimization",
|
|
"sustainability": "google-cloud-waf-sustainability",
|
|
}
|
|
|
|
|
|
def test_model_for_role_falls_back_to_default():
|
|
bundle = load_provider("gcp")
|
|
|
|
assert bundle.models.for_role("no-such-role") == bundle.models.default
|
|
|
|
|
|
def test_unknown_provider_is_rejected(tmp_path):
|
|
(tmp_path / "providers").mkdir()
|
|
|
|
with pytest.raises(ProviderConfigError, match="aws"):
|
|
load_provider("aws", root=tmp_path)
|
|
|
|
|
|
def minimal_bundle(tmp_path: Path, **overrides) -> dict:
|
|
skill_dir = tmp_path / "skills" / "alpha"
|
|
skill_dir.mkdir(parents=True)
|
|
(skill_dir / "SKILL.md").write_text(
|
|
"---\nname: alpha\ndescription: d\n---\n", encoding="utf-8"
|
|
)
|
|
(tmp_path / "template.md").write_text("# Template\n", encoding="utf-8")
|
|
config = {
|
|
"name": "test",
|
|
"skills_dirs": ["skills"],
|
|
"output_template": "template.md",
|
|
"models": {"default": "gemini/test-model"},
|
|
"tools": {"general": ["mermaid_check"], "cloud_read": []},
|
|
"mcp_auth": {"kind": "google_adc"},
|
|
"mcp_servers": {
|
|
"docs": {"url": "https://example.com/mcp", "tier": "general", "allow": []}
|
|
},
|
|
"role_mcp_servers": {"describer": ["docs"]},
|
|
}
|
|
config.update(overrides)
|
|
return config
|
|
|
|
|
|
def write_bundle(tmp_path: Path, config: dict) -> None:
|
|
(tmp_path / "providers").mkdir(exist_ok=True)
|
|
(tmp_path / "providers" / "test.yaml").write_text(
|
|
yaml.safe_dump(config), encoding="utf-8"
|
|
)
|
|
|
|
|
|
def test_minimal_bundle_loads(tmp_path):
|
|
write_bundle(tmp_path, minimal_bundle(tmp_path))
|
|
|
|
bundle = load_provider("test", root=tmp_path)
|
|
|
|
assert list(bundle.skills) == ["alpha"]
|
|
assert bundle.mcp_servers["docs"].allow == ()
|
|
assert bundle.mcp_servers["docs"].preview is False
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("override", "message"),
|
|
[
|
|
({"name": "other"}, "name"),
|
|
({"skills_dirs": ["missing"]}, "skills_dirs"),
|
|
({"output_template": "missing.md"}, "output_template"),
|
|
({"models": {}}, "models.default"),
|
|
({"tools": {"mutating": ["terraform_apply"]}}, "tier"),
|
|
(
|
|
{
|
|
"mcp_servers": {
|
|
"docs": {
|
|
"url": "http://example.com/mcp",
|
|
"tier": "general",
|
|
"allow": [],
|
|
}
|
|
}
|
|
},
|
|
"https",
|
|
),
|
|
(
|
|
{
|
|
"mcp_servers": {
|
|
"docs": {
|
|
"url": "https://example.com/mcp",
|
|
"tier": "write",
|
|
"allow": [],
|
|
}
|
|
}
|
|
},
|
|
"tier",
|
|
),
|
|
(
|
|
{
|
|
"mcp_servers": {
|
|
"docs": {"url": "https://example.com/mcp", "tier": "general"}
|
|
}
|
|
},
|
|
"allow",
|
|
),
|
|
({"role_mcp_servers": {"describer": ["missing"]}}, "missing"),
|
|
({"role_skills": {"describer": ["no-such-skill"]}}, "no-such-skill"),
|
|
({"pillar_skills": {"security": "no-such-skill"}}, "no-such-skill"),
|
|
],
|
|
)
|
|
def test_invalid_bundles_are_rejected(tmp_path, override, message):
|
|
write_bundle(tmp_path, minimal_bundle(tmp_path, **override))
|
|
|
|
with pytest.raises(ProviderConfigError, match=message):
|
|
load_provider("test", root=tmp_path)
|