Files
gcp_solution_architecture_a…/tests/test_agent_skills.py
Jonathan Boniface 2976dfab21 feat: vendor upstream Skills and add the GCP provider bundle
Increment 2 of .scratch/solution-architect-agent/spec.md.

- Vendor google-cloud-solution-architecture and the six
  google-cloud-waf-* Skills from google/skills@81a31a6, unmodified,
  with LICENSE, SHA256SUMS and VENDOR.md; add
  scripts/sync-vendored-skills.sh to re-sync at a pinned sha.
- app/agent_skills.py: discover Skills and validate SKILL.md
  frontmatter against the Agent Skills specification.
- app/providers.py + providers/gcp.yaml: load and validate a Cloud
  provider bundle (Skills, output template, per-role models, tool
  tiers, remote MCP servers). MCP allowlists stay empty until the
  read-only review in increment 6.
- Settings CLOUD_PROVIDER and MCP_ENABLE_PREVIEW.
- 35 new tests; full suite 65 passed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 18:20:17 +01:00

91 lines
3.3 KiB
Python

"""Agent Skills (agentskills.io) discovery and frontmatter validation."""
from pathlib import Path
import pytest
from app.agent_skills import SkillFormatError, discover_skills, read_skill
def write_skill(
parent: Path, dirname: str, frontmatter: str, body: str = "# Instructions\n"
) -> Path:
skill_dir = parent / dirname
skill_dir.mkdir(parents=True)
(skill_dir / "SKILL.md").write_text(
f"---\n{frontmatter}\n---\n\n{body}", encoding="utf-8"
)
return skill_dir
def test_reads_valid_skill_with_optional_fields(tmp_path):
skill_dir = write_skill(
tmp_path,
"pdf-processing",
"name: pdf-processing\n"
"description: >-\n Extract PDF text. Use when handling PDFs.\n"
"license: Apache-2.0\n"
"compatibility: Requires poppler\n"
"metadata:\n category: Documents\n"
"allowed-tools: Read",
)
skill = read_skill(skill_dir)
assert skill.name == "pdf-processing"
assert skill.description == "Extract PDF text. Use when handling PDFs."
assert skill.path == skill_dir
@pytest.mark.parametrize(
("dirname", "frontmatter", "message"),
[
("PDF-Processing", "name: PDF-Processing\ndescription: d", "lowercase"),
("-pdf", "name: -pdf\ndescription: d", "lowercase"),
("pdf-", "name: pdf-\ndescription: d", "lowercase"),
("pdf--processing", "name: pdf--processing\ndescription: d", "lowercase"),
("pdf_processing", "name: pdf_processing\ndescription: d", "lowercase"),
("a" * 65, f"name: {'a' * 65}\ndescription: d", "64"),
("other-dir", "name: pdf-processing\ndescription: d", "directory"),
("pdf", "name: pdf", "description"),
("pdf", "name: pdf\ndescription: ''", "description"),
("pdf", f"name: pdf\ndescription: {'x' * 1025}", "1024"),
("pdf", f"name: pdf\ndescription: d\ncompatibility: {'x' * 501}", "500"),
("pdf", "name: pdf\ndescription: d\nmetadata:\n version: 2", "metadata"),
("pdf", "name: pdf\ndescription: d\nphase: design", "phase"),
],
)
def test_rejects_invalid_frontmatter(tmp_path, dirname, frontmatter, message):
skill_dir = write_skill(tmp_path, dirname, frontmatter)
with pytest.raises(SkillFormatError, match=message):
read_skill(skill_dir)
def test_rejects_skill_without_frontmatter(tmp_path):
skill_dir = tmp_path / "pdf"
skill_dir.mkdir()
(skill_dir / "SKILL.md").write_text("# No frontmatter\n", encoding="utf-8")
with pytest.raises(SkillFormatError, match="frontmatter"):
read_skill(skill_dir)
def test_discovers_immediate_skill_directories_only(tmp_path):
root = tmp_path / "skills"
write_skill(root, "alpha", "name: alpha\ndescription: first")
write_skill(root / "vendor" / "google", "beta", "name: beta\ndescription: nested")
(root / "notes").mkdir()
skills = discover_skills([root, root / "vendor" / "google"])
assert sorted(skills) == ["alpha", "beta"]
def test_rejects_duplicate_skill_names_across_directories(tmp_path):
write_skill(tmp_path / "one", "alpha", "name: alpha\ndescription: first")
write_skill(tmp_path / "two", "alpha", "name: alpha\ndescription: second")
with pytest.raises(SkillFormatError, match="alpha"):
discover_skills([tmp_path / "one", tmp_path / "two"])