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>
This commit is contained in:
90
tests/test_agent_skills.py
Normal file
90
tests/test_agent_skills.py
Normal file
@@ -0,0 +1,90 @@
|
||||
"""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"])
|
||||
163
tests/test_providers.py
Normal file
163
tests/test_providers.py
Normal file
@@ -0,0 +1,163 @@
|
||||
"""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_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"),
|
||||
],
|
||||
)
|
||||
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)
|
||||
53
tests/test_vendored_skills.py
Normal file
53
tests/test_vendored_skills.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""Vendored upstream Skills stay byte-for-byte what VENDOR.md says they are."""
|
||||
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
|
||||
from app.agent_skills import discover_skills
|
||||
|
||||
VENDOR_DIR = Path(__file__).parents[1] / "skills" / "vendor" / "google"
|
||||
PINNED_COMMIT = "81a31a6e4300425598a69fd96c8e843c947ae308"
|
||||
EXPECTED_SKILLS = {
|
||||
"google-cloud-solution-architecture",
|
||||
"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",
|
||||
}
|
||||
|
||||
|
||||
def read_checksums() -> dict[str, str]:
|
||||
entries = {}
|
||||
for line in (VENDOR_DIR / "SHA256SUMS").read_text(encoding="utf-8").splitlines():
|
||||
digest, relative_path = line.split(maxsplit=1)
|
||||
entries[relative_path] = digest
|
||||
return entries
|
||||
|
||||
|
||||
def test_vendor_record_names_pinned_commit_and_licence():
|
||||
vendor_md = (VENDOR_DIR / "VENDOR.md").read_text(encoding="utf-8")
|
||||
|
||||
assert f"`{PINNED_COMMIT}`" in vendor_md
|
||||
assert "Apache License" in (VENDOR_DIR / "LICENSE").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_checksums_cover_every_vendored_file_and_match():
|
||||
checksums = read_checksums()
|
||||
on_disk = {
|
||||
path.relative_to(VENDOR_DIR).as_posix()
|
||||
for path in VENDOR_DIR.rglob("*")
|
||||
if path.is_file() and path.name not in {"SHA256SUMS", "VENDOR.md"}
|
||||
}
|
||||
|
||||
assert set(checksums) == on_disk
|
||||
for relative_path, digest in checksums.items():
|
||||
actual = hashlib.sha256((VENDOR_DIR / relative_path).read_bytes()).hexdigest()
|
||||
assert actual == digest, f"{relative_path} differs from vendored upstream"
|
||||
|
||||
|
||||
def test_expected_upstream_skills_are_present_and_valid():
|
||||
skills = discover_skills([VENDOR_DIR])
|
||||
|
||||
assert set(skills) == EXPECTED_SKILLS
|
||||
Reference in New Issue
Block a user