mirror of
https://codeberg.org/dabao1955/apk-reverse.git
synced 2026-12-04 04:30:23 +08:00
Add a manifest and marketplace for each host. Both wrap the existing skills/apk-reverse/ tree without duplicating it. Document both install routes in both READMEs, switch all repository links to the Codeberg remote, and add offline manifest tests. A real install round-trip stays unverified: neither CLI is installed here.
140 lines
5.7 KiB
Python
140 lines
5.7 KiB
Python
"""The two plugin wrappers must point at the one skill that actually ships.
|
|
|
|
Neither `claude` nor `codex` is installed in CI, so this cannot prove a real install
|
|
works -- that stays `unverified`. What it can prove without either binary is the
|
|
part that silently breaks first: a manifest with a missing field, a path that does
|
|
not resolve, or two plugins that disagree about what they wrap. The checks mirror
|
|
the published manifest rules (required keys, `./`-relative component paths, no
|
|
`..`, marketplace entry source resolving to the plugin root).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
from urllib.parse import urlparse
|
|
|
|
import pytest
|
|
|
|
from conftest import REPO_ROOT
|
|
|
|
pytestmark = pytest.mark.unit
|
|
|
|
CLAUDE_PLUGIN = REPO_ROOT / ".claude-plugin" / "plugin.json"
|
|
CLAUDE_MARKETPLACE = REPO_ROOT / ".claude-plugin" / "marketplace.json"
|
|
CODEX_PLUGIN = REPO_ROOT / ".codex-plugin" / "plugin.json"
|
|
CODEX_MARKETPLACE = REPO_ROOT / ".agents" / "plugins" / "marketplace.json"
|
|
ALL = (CLAUDE_PLUGIN, CLAUDE_MARKETPLACE, CODEX_PLUGIN, CODEX_MARKETPLACE)
|
|
SKILL = REPO_ROOT / "skills" / "apk-reverse" / "SKILL.md"
|
|
|
|
NAME = "apk-reverse"
|
|
NAME_RE = re.compile(r"^[a-z0-9]+(?:-[a-z0-9]+)*$")
|
|
|
|
|
|
def load(path):
|
|
with path.open(encoding="utf-8") as fh:
|
|
data = json.load(fh)
|
|
assert isinstance(data, dict), "%s is not a JSON object" % path
|
|
return data
|
|
|
|
|
|
@pytest.mark.parametrize("path", ALL, ids=lambda p: str(p.relative_to(REPO_ROOT)))
|
|
def test_manifest_exists_parses_and_names_the_plugin(path):
|
|
data = load(path)
|
|
assert data["name"] == NAME
|
|
assert NAME_RE.match(data["name"])
|
|
|
|
|
|
def test_both_plugin_manifests_agree_on_identity():
|
|
claude = load(CLAUDE_PLUGIN)
|
|
codex = load(CODEX_PLUGIN)
|
|
for field in ("name", "version", "description", "license"):
|
|
assert claude[field] == codex[field], field
|
|
for field in ("homepage", "repository"):
|
|
assert urlparse(claude[field]).scheme == "https", field
|
|
assert claude[field] == codex[field], field
|
|
# Codex requires semver; Claude pins whatever string it is given. One version
|
|
# for both keeps an upgrade from silently changing one side only.
|
|
assert re.match(r"^\d+\.\d+\.\d+$", claude["version"])
|
|
assert claude["license"] == "MIT"
|
|
|
|
|
|
def test_claude_marketplace_entry_resolves_to_the_plugin_root():
|
|
data = load(CLAUDE_MARKETPLACE)
|
|
assert NAME_RE.match(data["name"])
|
|
assert data["owner"]["name"]
|
|
assert isinstance(data["plugins"], list) and len(data["plugins"]) == 1
|
|
entry = data["plugins"][0]
|
|
assert entry["name"] == NAME == load(CLAUDE_PLUGIN)["name"]
|
|
assert entry["description"]
|
|
# "." is the documented relative source for a plugin at the marketplace root.
|
|
assert entry["source"] == "."
|
|
assert (REPO_ROOT / entry["source"]).resolve() == REPO_ROOT.resolve()
|
|
|
|
|
|
def test_codex_marketplace_entry_resolves_to_the_plugin_root():
|
|
data = load(CODEX_MARKETPLACE)
|
|
assert NAME_RE.match(data["name"])
|
|
assert data["interface"]["displayName"]
|
|
assert len(data["plugins"]) == 1
|
|
entry = data["plugins"][0]
|
|
assert entry["name"] == NAME == load(CODEX_PLUGIN)["name"]
|
|
source = entry["source"]
|
|
assert source["source"] == "local"
|
|
assert source["path"].startswith("./")
|
|
assert (REPO_ROOT / source["path"]).resolve() == REPO_ROOT.resolve()
|
|
assert entry["policy"]["installation"] == "AVAILABLE"
|
|
assert entry["policy"]["authentication"] == "ON_INSTALL"
|
|
assert entry["category"]
|
|
|
|
|
|
def test_codex_skills_component_points_at_the_shipped_skill():
|
|
data = load(CODEX_PLUGIN)
|
|
value = data["skills"]
|
|
assert isinstance(value, str) and value.startswith("./")
|
|
assert ".." not in Path(value).parts
|
|
target = (REPO_ROOT / value).resolve()
|
|
assert target == (REPO_ROOT / "skills").resolve()
|
|
assert (target / NAME / "SKILL.md").is_file()
|
|
|
|
# Install-surface copy is validated by Codex: <=125 chars, at most 3 prompts
|
|
# of <=128 chars each. Re-implementing that here catches a bad edit offline.
|
|
interface = data["interface"]
|
|
assert 0 < len(interface["shortDescription"]) <= 125
|
|
prompts = interface["defaultPrompt"]
|
|
assert 1 <= len(prompts) <= 3
|
|
assert all(0 < len(p) <= 128 for p in prompts)
|
|
|
|
|
|
def test_the_wrapped_skill_has_valid_frontmatter():
|
|
assert SKILL.is_file()
|
|
text = SKILL.read_text(encoding="utf-8")
|
|
match = re.match(r"^---\r?\n(.*?)\r?\n---\r?\n", text, re.S)
|
|
assert match, "SKILL.md has no frontmatter"
|
|
front = match.group(1)
|
|
name = re.search(r"^name:\s*(.+)$", front, re.M)
|
|
description = re.search(r"^description:\s*(.+)$", front, re.M)
|
|
assert name and name.group(1).strip() == NAME
|
|
assert description and 40 <= len(description.group(1).strip()) <= 1024
|
|
|
|
|
|
def test_no_manifest_path_is_absolute_or_escapes_the_repo():
|
|
"""Every path-looking value in all four files stays inside the repo."""
|
|
def walk(value, origin):
|
|
if isinstance(value, dict):
|
|
for key, item in value.items():
|
|
walk(item, "%s.%s" % (origin, key))
|
|
elif isinstance(value, list):
|
|
for index, item in enumerate(value):
|
|
walk(item, "%s[%d]" % (origin, index))
|
|
elif isinstance(value, str) and (value.startswith(("./", "/")) or "/.." in value):
|
|
assert not value.startswith("/"), "%s: absolute path %r" % (origin, value)
|
|
assert ".." not in Path(value).parts, "%s: traversal in %r" % (origin, value)
|
|
target = (REPO_ROOT / value).resolve()
|
|
assert target == REPO_ROOT or REPO_ROOT.resolve() in target.parents, \
|
|
"%s: %r resolves outside the repository" % (origin, value)
|
|
assert target.exists(), "%s: %r does not resolve" % (origin, value)
|
|
|
|
for path in ALL:
|
|
walk(load(path), path.relative_to(REPO_ROOT).as_posix())
|