From f362b20e900cfc64b2eadc22ed53f74e5a87f0f5 Mon Sep 17 00:00:00 2001 From: Timothy Kassis Date: Tue, 29 Sep 2026 15:31:00 -0700 Subject: [PATCH] Enhance testing and validation for Agent Plugins - Added `jsonschema` as a development dependency to validate `plugin.json` against the official schema. - Updated `tests/_meta` to include checks for package-path containment and version synchronization. - Revised `skill-tests.yml` to trigger tests on changes to `plugin.json` and ensure CI runs the new validation checks. - Improved unit tests to ensure plugin manifests conform to the schema and maintain proper structure within the plugin root. --- .github/workflows/skill-tests.yml | 7 + AGENTS.md | 8 +- CONTRIBUTING.md | 7 +- pyproject.toml | 1 + tests/_meta/schemas/Apache-2.0.txt | 202 +++++++++++++++++++ tests/_meta/schemas/plugin-1.0.0.schema.json | 65 ++++++ tests/_meta/test_repo_contract.py | 54 ++--- 7 files changed, 315 insertions(+), 29 deletions(-) create mode 100644 tests/_meta/schemas/Apache-2.0.txt create mode 100644 tests/_meta/schemas/plugin-1.0.0.schema.json diff --git a/.github/workflows/skill-tests.yml b/.github/workflows/skill-tests.yml index a8e00273..6a0a9cdd 100644 --- a/.github/workflows/skill-tests.yml +++ b/.github/workflows/skill-tests.yml @@ -5,6 +5,7 @@ on: paths: - "skills/**" - "tests/**" + - "plugin.json" - "pyproject.toml" - "uv.lock" - ".github/workflows/skill-tests.yml" @@ -14,6 +15,10 @@ on: paths: - "skills/**" - "tests/**" + - "plugin.json" + - "pyproject.toml" + - "uv.lock" + - ".github/workflows/skill-tests.yml" workflow_dispatch: permissions: @@ -49,6 +54,8 @@ jobs: # a skill shipping scripts/ has a suite under tests/ and an entry in # tests/skill-requirements.toml. It imports no skill code and needs no # scientific packages, so it runs in seconds on every pull request. + # It also validates plugin.json against the bundled Agent Plugins schema, + # checks package-path containment, and keeps the collection version in sync. - name: Structural contract and coverage run: uv run --python 3.13 python -m pytest tests/_meta -q diff --git a/AGENTS.md b/AGENTS.md index 1b56a4a7..4ccce5cc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -248,9 +248,11 @@ refuses such a session; `tests/run_all.py` forks per skill. uv run --with pytest python -m pytest tests/_meta -q ``` -`tests/_meta` is the fastest useful signal in the repo: pure standard library, no scientific -packages, a couple of seconds. It runs the shared structural contract against **every** skill and -fails if a skill ships `scripts/` without a suite under `tests//` or an entry in +`tests/_meta` is the fastest useful signal in the repo: no scientific packages, a couple of +seconds. It uses `jsonschema` from the dev dependencies to validate `plugin.json` against the +bundled official Agent Plugins schema, without network access. It also checks package-path +containment and version synchronization. It runs the shared structural contract against **every** +skill and fails if a skill ships `scripts/` without a suite under `tests//` or an entry in `tests/skill-requirements.toml`. `.github/workflows/skill-tests.yml` runs it on every pull request, so a skill with untested scripts cannot land. A full run of `tests/run_all.py` starts with it. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af14db79..6fcac449 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,10 @@ Participation in this project is governed by our [Code of Conduct](CODE_OF_CONDU All repository skills live under `skills/`. The repository root is also an [Agent Plugins](https://agent-plugins.org/) package: keep root `plugin.json` schema-valid, do not add non-portable top-level fields, and keep its `version` in sync with `pyproject.toml` whenever -you bump the collection version. +you bump the collection version. After `uv sync`, run +`uv run python -m pytest tests/_meta -q` to check the manifest against the bundled official +1.0.0 JSON Schema, version synchronization, package-path containment, and skill structure. +These checks run in CI on manifest-only changes as well as skill changes. ```text plugin.json @@ -333,7 +336,7 @@ Nothing is installed into the project environment, so `uv sync` is unaffected. E A new skill that ships `scripts/` needs a `[skills.]` entry — `tests/_meta` fails without one. Use `packages = []` when its bundled tooling is standard-library only — the skill still gets a clean environment with just pytest. uv caches wheels globally, so repeat runs create each environment in milliseconds. -`.github/workflows/skill-tests.yml` runs `tests/_meta` plus every `packages = []` suite on each pull request, which is fast and needs no wheels beyond pytest. The full `--isolated` sweep is not run in CI: it builds an environment per skill, and several of them need a CUDA toolchain, a JDK, or a local MATLAB install that a runner does not have. Run it locally before a release, and whenever you change anything under `tests/_contract/`. +`.github/workflows/skill-tests.yml` runs `tests/_meta` in the project environment (including the `jsonschema` dev dependency) plus every `packages = []` suite on each relevant pull request. Those isolated skill suites need no wheels beyond pytest. The full `--isolated` sweep is not run in CI: it builds an environment per skill, and several of them need a CUDA toolchain, a JDK, or a local MATLAB install that a runner does not have. Run it locally before a release, and whenever you change anything under `tests/_contract/`. ## Pull Request Checklist diff --git a/pyproject.toml b/pyproject.toml index f4a6ceea..b3374be0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ dependencies = [ [dependency-groups] dev = [ + "jsonschema>=4.26.0", "skills-ref @ git+https://github.com/agentskills/agentskills.git#subdirectory=skills-ref", ] diff --git a/tests/_meta/schemas/Apache-2.0.txt b/tests/_meta/schemas/Apache-2.0.txt new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/tests/_meta/schemas/Apache-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/tests/_meta/schemas/plugin-1.0.0.schema.json b/tests/_meta/schemas/plugin-1.0.0.schema.json new file mode 100644 index 00000000..8fed0e1f --- /dev/null +++ b/tests/_meta/schemas/plugin-1.0.0.schema.json @@ -0,0 +1,65 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", + "title": "Agent Plugins Manifest", + "description": "Machine-readable schema for plugin.json in Agent Plugins 1.0.0. The Agent Plugins specification defines additional semantic and operational requirements.", + "type": "object", + "properties": { + "$schema": { + "const": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", + "description": "Canonical identifier of the plugin manifest schema for the Agent Plugins version targeted by this document." + }, + "name": { + "type": "string", + "minLength": 1, + "maxLength": 64, + "pattern": "^(?!.*(?:--|\\.\\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$", + "description": "Human-readable plugin name." + }, + "version": { + "type": "string" + }, + "description": { + "type": "string" + }, + "author": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "email": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": false + }, + "homepage": { + "type": "string" + }, + "repository": { + "type": "string" + }, + "license": { + "type": "string" + }, + "keywords": { + "type": "array", + "items": { + "type": "string" + } + }, + "extensions": { + "type": "object", + "description": "Client-specific manifest data keyed by reverse-domain extension namespace. Agent Plugins assigns no semantics to namespace object contents.", + "additionalProperties": { + "type": "object" + } + } + }, + "required": ["$schema", "name"], + "additionalProperties": false +} diff --git a/tests/_meta/test_repo_contract.py b/tests/_meta/test_repo_contract.py index b366b8e3..9110397c 100644 --- a/tests/_meta/test_repo_contract.py +++ b/tests/_meta/test_repo_contract.py @@ -15,11 +15,12 @@ run it on every pull request in seconds. from __future__ import annotations import json -import re import tomllib import unittest from pathlib import Path +from jsonschema import Draft202012Validator + import skill_contract REPO_ROOT = Path(__file__).resolve().parents[2] @@ -31,21 +32,11 @@ PYPROJECT = REPO_ROOT / "pyproject.toml" PLUGIN_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json" PLUGIN_NAME = "scientific-agent-skills" -ALLOWED_PLUGIN_KEYS = frozenset( - { - "$schema", - "name", - "version", - "description", - "author", - "homepage", - "repository", - "license", - "keywords", - "extensions", - } -) -PLUGIN_NAME_RE = re.compile(r"^(?!.*(?:--|\.\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$") +# Unmodified schema from PLUGIN_SCHEMA, retrieved 2026-09-29. Upstream source: +# https://github.com/agentplugins/agent-plugins-spec/tree/main/schemas/1.0.0 +# Apache-2.0; the upstream license is bundled alongside the schema. Keep this +# versioned copy local so tests neither fetch nor execute remote content. +PLUGIN_SCHEMA_FILE = Path(__file__).parent / "schemas" / "plugin-1.0.0.schema.json" structure = skill_contract.structure office = skill_contract.office @@ -158,14 +149,17 @@ class AgentPluginTests(unittest.TestCase): def test_plugin_manifest_conforms(self) -> None: self.assertTrue(PLUGIN_MANIFEST.is_file(), "plugin.json must exist at the repo root") manifest = json.loads(PLUGIN_MANIFEST.read_text(encoding="utf-8")) - self.assertIsInstance(manifest, dict) - - unknown = sorted(set(manifest) - ALLOWED_PLUGIN_KEYS) - self.assertEqual(unknown, [], "plugin.json has closed top-level schema") + schema = json.loads(PLUGIN_SCHEMA_FILE.read_text(encoding="utf-8")) + self.assertEqual(schema["$id"], PLUGIN_SCHEMA) + Draft202012Validator.check_schema(schema) + errors = [ + f"{error.json_path}: {error.message}" + for error in Draft202012Validator(schema).iter_errors(manifest) + ] + self.assertEqual(errors, [], "plugin.json must satisfy the official schema") self.assertEqual(manifest.get("$schema"), PLUGIN_SCHEMA) self.assertEqual(manifest.get("name"), PLUGIN_NAME) - self.assertRegex(manifest["name"], PLUGIN_NAME_RE) project = tomllib.loads(PYPROJECT.read_text(encoding="utf-8"))["project"] self.assertEqual( @@ -178,12 +172,24 @@ class AgentPluginTests(unittest.TestCase): """Agent Plugins discovers only immediate children of skills/ with SKILL.md.""" self.assertTrue(SKILLS_DIR.is_dir()) self.assertTrue(KNOWN_SKILLS, "no discoverable skills under skills/") - for name in sorted(KNOWN_SKILLS): - with self.subTest(skill=name): - skill_md = SKILLS_DIR / name / "SKILL.md" + for skill in sorted(SKILLS_DIR.iterdir()): + if not skill.is_dir(): + continue + with self.subTest(skill=skill.name): + skill_md = skill / "SKILL.md" self.assertTrue(skill_md.is_file()) self.assertEqual(skill_md.parent.parent, SKILLS_DIR) + def test_package_paths_stay_within_plugin_root(self) -> None: + """Section 4.1 permits internal symlinks but rejects escaping package paths.""" + root = REPO_ROOT.resolve() + for path in [PLUGIN_MANIFEST, SKILLS_DIR, *SKILLS_DIR.rglob("*")]: + with self.subTest(path=str(path.relative_to(REPO_ROOT))): + self.assertTrue( + path.resolve().is_relative_to(root), + f"{path.relative_to(REPO_ROOT)} resolves outside the plugin root", + ) + if __name__ == "__main__": unittest.main()