Skip to content

Open-source skills for designing and reviewing software with AI agents

Handle scalar agent paths when packaging (#229)

Amit Vijapurbcf0394a11c6
diff --git a/scripts/pack_plugin.py b/scripts/pack_plugin.py
index 1d60296..95ba102 100644
--- a/scripts/pack_plugin.py
+++ b/scripts/pack_plugin.py
@@ -84,7 +84,10 @@ def build(root: Path, target: str, output: Path) -> tuple[Path, Path]:
for metadata in (manifest, portable, openai):
if any(metadata.get(key) for key in ("mcpServers", "mcp", "apps")):
raise ValueError("This runtime builder does not package MCP or app dependencies")
- references = list(manifest.get("agents", []))
+ agents = manifest.get("agents", [])
+ if not isinstance(agents, (str, list)):
+ raise ValueError(f"Invalid manifest agents: {agents!r}")
+ references = [agents] if isinstance(agents, str) else list(agents)
interface = openai.get("interface", {})
if target == "openai":
interface = interface or manifest.get("interface", {})
diff --git a/tests/unit/test_packaging.py b/tests/unit/test_packaging.py
index 6c8f771..5fab84c 100644
--- a/tests/unit/test_packaging.py
+++ b/tests/unit/test_packaging.py
@@ -163,6 +163,62 @@ def test_rejects_escaping_or_missing_manifest_assets(
build(source, "openai", tmp_path / "output")
[email protected]("agents", [
+ "./.claude-plugin/agents/style.md", ["./.claude-plugin/agents/style.md"],
+])
+def test_claude_agent_reference_forms(
+ source: Path, tmp_path: Path, agents: str | list[str],
+) -> None:
+ path = source / ".claude-plugin/plugin.json"
+ manifest = json.loads(path.read_text())
+ manifest["agents"] = agents
+ path.write_text(json.dumps(manifest))
+ folder, archive = build(source, "claude", tmp_path / "output")
+ reference = ".claude-plugin/agents/style.md"
+ assert (folder / reference).read_bytes() == (source / reference).read_bytes()
+ assert (folder / ".claude-plugin/plugin.json").read_bytes() == path.read_bytes()
+ with zipfile.ZipFile(archive) as bundle:
+ assert bundle.read(reference) == (source / reference).read_bytes()
+ assert bundle.read(".claude-plugin/plugin.json") == path.read_bytes()
+
+
[email protected]("target,directory", [
+ ("claude", ".claude-plugin"), ("openai", ".codex-plugin"),
+])
[email protected]("agents", [
+ None, 5, True, {}, {"./agents/style.md": None}, 1.5,
+])
+def test_rejects_invalid_manifest_agents(
+ source: Path, tmp_path: Path, target: str, directory: str, agents: object,
+) -> None:
+ path = source / directory / "plugin.json"
+ manifest = json.loads(path.read_text())
+ manifest["agents"] = agents
+ path.write_text(json.dumps(manifest))
+ output = tmp_path / "output"
+ with pytest.raises(ValueError) as error:
+ build(source, target, output)
+ assert str(error.value) == f"Invalid manifest agents: {agents!r}"
+ assert not output.exists()
+
+
[email protected]("reference", [
+ "./.claude-plugin/agents/missing.md", "../escape.md", "/tmp/agent.md",
+])
+def test_rejects_escaping_or_missing_scalar_agent_references(
+ source: Path, tmp_path: Path, reference: str,
+) -> None:
+ path = source / ".claude-plugin/plugin.json"
+ manifest = json.loads(path.read_text())
+ manifest["agents"] = reference
+ path.write_text(json.dumps(manifest))
+ output = tmp_path / "output"
+ with pytest.raises(ValueError) as error:
+ build(source, "claude", output)
+ assert str(error.value) == f"Unbundled manifest reference: {reference}"
+ assert not output.exists()
+
+
@pytest.mark.parametrize("key", ["composerIcon", "logo"])
def test_rejects_missing_openai_interface_icons(
source: Path, tmp_path: Path, key: str,