mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 13:19:23 +08:00
fix(catalog): 校验技能指针的客户端契约,撤回 REA 的单段版本 / validate skill pointers against the client contract (#239)
客户端按 `marketSkillEntrySchema` 校验 `entry.json`,`latestVersion` 只接受 `x.y` 或 `x.y.z`, 不通过的条目在索引时被跳过。#227 写入的上游修订号 `50` 让所有客户端都看不到 reverse-engineer-anything,而 manifest 仍计入它。 - reverse-engineer-anything 恢复为 `release: unknown` 且不声明 `latestVersion`;固定提交与合规审查不变。 - video-use 去掉指针无法声明的 `skillType`,此前客户端一直拒绝这份 sidecar。 - 校验器用导出的客户端 Schema 校验技能指针,并按客户端判据双向比较 sidecar 事实。 Clients skip any `entry.json` whose `latestVersion` is not `x.y` or `x.y.z`, so the upstream revision `50` from #227 hid reverse-engineer-anything from every client. This restores the shape reviewed in #212, drops a `skillType` from video-use that made clients reject its sidecar, and makes the validator enforce the client contract for skill pointers and compare sidecar facts both ways. 验证 / Validation: `validate_catalog_metadata.py --require-complete` 0 errors;真实 MarketSync 与校验器在 43 类变异下判定一致;索引 145 技能、9 Agent、2 团队,0 个 sidecar 被拒。
This commit is contained in:
10 files changed
+592
-81
No files matched your search
@@ -32,6 +32,46 @@ def unknown() -> dict[str, str]:
|
||||
return {"state": "unknown"}
|
||||
|
||||
|
||||
def known_release(version: str, scheme: str = "opaque"):
|
||||
return lambda payload: payload.update(release={"state": "known", "version": version, "versionScheme": scheme})
|
||||
|
||||
|
||||
def add_single_child_collection(payload: dict) -> None:
|
||||
child_presentation = copy.deepcopy(payload["presentation"])
|
||||
child_presentation["tags"] = []
|
||||
child_presentation["i18n"] = {
|
||||
"zh-CN": {"name": "child-one", "summary": "Same child summary"},
|
||||
"en-US": {"name": "child-one", "summary": "Same child summary"},
|
||||
}
|
||||
payload["spec"]["collection"] = {
|
||||
"role": "parent",
|
||||
"childCount": 1,
|
||||
"children": [
|
||||
{
|
||||
"identity": {
|
||||
"kind": "skill",
|
||||
"id": "child-one",
|
||||
"parentId": "example-skill",
|
||||
},
|
||||
"path": "skills/child-one",
|
||||
"presentation": child_presentation,
|
||||
"release": unknown(),
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def single_child_entry() -> dict[str, object]:
|
||||
return {
|
||||
"id": "child-one",
|
||||
"path": "skills/child-one",
|
||||
"i18n": {
|
||||
"zh-CN": {"shortDesc": "Same child summary"},
|
||||
"en-US": {"shortDesc": "Same child summary"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def valid_entry() -> dict[str, object]:
|
||||
return {
|
||||
"id": "example-skill",
|
||||
@@ -168,7 +208,7 @@ def valid_sidecar() -> dict[str, object]:
|
||||
"upstreamMaintainer": {"name": "Example Maintainer", "verified": False},
|
||||
},
|
||||
"compatibility": {"platforms": unknown()},
|
||||
"spec": {"kind": "skill", "riskLevel": "low"},
|
||||
"spec": {"kind": "skill"},
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +218,11 @@ class CatalogMetadataValidatorTests(unittest.TestCase):
|
||||
self.root = Path(self.tempdir.name)
|
||||
(self.root / "schemas").mkdir()
|
||||
shutil.copyfile(SOURCE_SCHEMA, self.root / "schemas" / SOURCE_SCHEMA.name)
|
||||
for client_schema in (VALIDATOR.AGENT_ENTRY_SCHEMA_NAME, VALIDATOR.TEAM_ENTRY_SCHEMA_NAME):
|
||||
for client_schema in (
|
||||
VALIDATOR.AGENT_ENTRY_SCHEMA_NAME,
|
||||
VALIDATOR.SKILL_ENTRY_SCHEMA_NAME,
|
||||
VALIDATOR.TEAM_ENTRY_SCHEMA_NAME,
|
||||
):
|
||||
shutil.copyfile(SOURCE_SCHEMA.with_name(client_schema), self.root / "schemas" / client_schema)
|
||||
(self.root / "agents").mkdir()
|
||||
(self.root / "teams").mkdir()
|
||||
@@ -211,6 +255,16 @@ class CatalogMetadataValidatorTests(unittest.TestCase):
|
||||
mutate(payload)
|
||||
self.write_json(self.sidecar_path, payload)
|
||||
|
||||
def write_skill_pointer_case(self, mutate_entry=None, mutate_sidecar=None) -> None:
|
||||
entry = valid_entry()
|
||||
sidecar = valid_sidecar()
|
||||
if mutate_entry:
|
||||
mutate_entry(entry)
|
||||
if mutate_sidecar:
|
||||
mutate_sidecar(sidecar)
|
||||
self.write_json(self.entry_path, entry)
|
||||
self.write_json(self.sidecar_path, sidecar)
|
||||
|
||||
def write_agent_case(self, install_policy: str | None, update_policy: str | None, availability: str) -> None:
|
||||
agent_dir = self.root / "agents" / "system-agent"
|
||||
agent_dir.mkdir()
|
||||
@@ -652,6 +706,180 @@ class CatalogMetadataValidatorTests(unittest.TestCase):
|
||||
self.write_agent_pointer_case(entry_change, metadata_change)
|
||||
self.assertTrue(any(issue.rule == "agent-entry-schema" for issue in self.validate().issues))
|
||||
|
||||
def test_rejects_skill_pointer_the_client_would_drop_even_if_sidecar_repeats_it(self) -> None:
|
||||
# The client skips such an entry while indexing: the listing disappears for every
|
||||
# user while manifest.stats.totalSkills keeps counting it.
|
||||
cases = [
|
||||
(lambda p: p.update(latestVersion="50"), known_release("50")),
|
||||
(lambda p: p.update(latestVersion="1.2.3.4"), known_release("1.2.3.4")),
|
||||
(lambda p: p.update(latestVersion="1.2.3-beta"), known_release("1.2.3-beta", "semver")),
|
||||
(lambda p: p.update(latestVersion=123), known_release("123")),
|
||||
(lambda p: p.update(latestVersion="١.٢"), known_release("١.٢")),
|
||||
(lambda p: p.update(requiredClientVersion="1.0"), None),
|
||||
(lambda p: p.update(version="1.2.3"), None),
|
||||
(lambda p: p.update(riskLevel="extreme"), None),
|
||||
(lambda p: p.update(id="Example_Skill"), None),
|
||||
(lambda p: p.pop("stewardship"), None),
|
||||
(lambda p: p["source"].update(kind="ftp"), None),
|
||||
(lambda p: p["maintainer"].update(verified="true"), None),
|
||||
]
|
||||
for index, (entry_change, metadata_change) in enumerate(cases):
|
||||
with self.subTest(index=index):
|
||||
self.write_skill_pointer_case(entry_change, metadata_change)
|
||||
self.assertTrue(any(issue.rule == "skill-entry-schema" for issue in self.validate().issues))
|
||||
|
||||
def test_rejects_skill_collection_shapes_the_client_rejects_outside_json_schema(self) -> None:
|
||||
cases = {
|
||||
"children with source.path": lambda p: (
|
||||
p.update(children=[single_child_entry()]),
|
||||
p["source"].update(path="skills/child-one"),
|
||||
),
|
||||
"duplicate child id": lambda p: p.update(children=[single_child_entry(), single_child_entry()]),
|
||||
}
|
||||
for name, entry_change in cases.items():
|
||||
with self.subTest(name):
|
||||
self.write_skill_pointer_case(entry_change, add_single_child_collection)
|
||||
self.assertTrue(any(issue.rule == "skill-entry-schema" for issue in self.validate().issues))
|
||||
|
||||
def test_rejects_skill_pointer_entry_id_that_is_not_the_catalog_slug(self) -> None:
|
||||
self.write_skill_pointer_case(lambda p: p.update(id="another-skill"))
|
||||
self.assertTrue(any("entry.id" in issue.message for issue in self.validate().issues))
|
||||
|
||||
def test_skill_pointer_accepts_every_version_form_the_client_admits(self) -> None:
|
||||
for version, scheme in (("1.3", "opaque"), ("1.2.3", "semver"), ("2026.9.19", "calver")):
|
||||
with self.subTest(version=version):
|
||||
self.write_skill_pointer_case(lambda p: p.update(latestVersion=version), known_release(version, scheme))
|
||||
self.assertFalse(self.validate().has_errors)
|
||||
|
||||
def test_release_must_equal_what_the_client_derives_from_the_pointer(self) -> None:
|
||||
# The client derives a release from latestVersion and rejects the whole sidecar on
|
||||
# any difference, which silently turns an installable listing into listing-only.
|
||||
cases = {
|
||||
"pointer knows, sidecar omits": (lambda p: p.update(latestVersion="1.2.3"), None),
|
||||
"different version": (lambda p: p.update(latestVersion="1.2.3"), known_release("1.2.4", "semver")),
|
||||
"only the sidecar knows": (None, known_release("1.2.3", "semver")),
|
||||
"opaque for a semver": (lambda p: p.update(latestVersion="1.2.3"), known_release("1.2.3")),
|
||||
"semver for a calver": (
|
||||
lambda p: p.update(latestVersion="2026.9.19"),
|
||||
known_release("2026.9.19", "semver"),
|
||||
),
|
||||
}
|
||||
for name, (entry_change, metadata_change) in cases.items():
|
||||
with self.subTest(name):
|
||||
self.write_skill_pointer_case(entry_change, metadata_change)
|
||||
self.assertTrue(
|
||||
any(issue.rule == "legacy-consistency" and "release" in issue.message
|
||||
for issue in self.validate().issues)
|
||||
)
|
||||
|
||||
def test_skill_pointer_sidecar_cannot_add_or_drop_facts_the_client_compares(self) -> None:
|
||||
# Each case made the client reject the sidecar while this validator stayed green.
|
||||
cases = {
|
||||
"skillType only in sidecar": (None, lambda p: p["spec"].update(skillType="procedural")),
|
||||
"riskLevel only in sidecar": (None, lambda p: p["spec"].update(riskLevel="high")),
|
||||
"riskLevel only in entry": (lambda p: p.update(riskLevel="high"), None),
|
||||
"riskLevel differs": (lambda p: p.update(riskLevel="low"), lambda p: p["spec"].update(riskLevel="high")),
|
||||
"client floor only in sidecar": (
|
||||
None,
|
||||
lambda p: p["compatibility"].update(requiredClientVersion="10.0.0"),
|
||||
),
|
||||
"client floor only in entry": (lambda p: p.update(requiredClientVersion="10.0.0"), None),
|
||||
"compatibleAgents only in sidecar": (None, lambda p: p["compatibility"].update(compatibleAgents=["x"])),
|
||||
"category only in sidecar": (lambda p: p.pop("category"), None),
|
||||
"tags only in sidecar": (lambda p: p.pop("tags"), None),
|
||||
"path only in sidecar": (None, lambda p: p["provenance"]["content"].update(path="extra/path")),
|
||||
}
|
||||
for name, (entry_change, metadata_change) in cases.items():
|
||||
with self.subTest(name):
|
||||
self.write_skill_pointer_case(entry_change, metadata_change)
|
||||
self.assertTrue(any(issue.rule == "legacy-consistency" for issue in self.validate().issues))
|
||||
|
||||
def test_agent_pointer_sidecar_cannot_add_facts_the_client_compares(self) -> None:
|
||||
cases = {
|
||||
"client floor only in sidecar": (lambda p: p.pop("requiredClientVersion"), None),
|
||||
"client floor only in entry": (None, lambda p: p["compatibility"].pop("requiredClientVersion")),
|
||||
"compatibleAgents only in sidecar": (None, lambda p: p["compatibility"].update(compatibleAgents=["x"])),
|
||||
"category only in sidecar": (lambda p: p.pop("category"), None),
|
||||
}
|
||||
for name, (entry_change, metadata_change) in cases.items():
|
||||
with self.subTest(name):
|
||||
self.write_agent_pointer_case(entry_change, metadata_change)
|
||||
self.assertTrue(any(issue.rule == "legacy-consistency" for issue in self.validate().issues))
|
||||
|
||||
def test_inline_agent_sidecar_must_match_the_facts_the_client_compares(self) -> None:
|
||||
self.write_agent_case("market", "market", "listing-only")
|
||||
agent_path = self.root / "agents" / "system-agent" / "agent.json"
|
||||
sidecar_path = self.root / "agents" / "system-agent" / VALIDATOR.SIDECAR_NAME
|
||||
self.write_json(self.root / "manifest.json", {
|
||||
"supportedLocales": ["zh-CN", "en-US"], "stats": {"totalAgents": 1, "totalSkills": 1},
|
||||
})
|
||||
agent = json.loads(agent_path.read_text(encoding="utf-8"))
|
||||
agent["i18n"]["en-US"]["tags"] = ["localized"]
|
||||
self.write_json(agent_path, agent)
|
||||
sidecar = json.loads(sidecar_path.read_text(encoding="utf-8"))
|
||||
sidecar["presentation"]["tags"] = ["localized"]
|
||||
self.write_json(sidecar_path, sidecar)
|
||||
self.assertFalse(self.validate().has_errors, "the default locale's tags are the legacy tags")
|
||||
|
||||
cases = {
|
||||
"tags differ": lambda p: p["presentation"].update(tags=["other"]),
|
||||
"client floor only in sidecar": lambda p: p["compatibility"].update(requiredClientVersion="10.0.0"),
|
||||
}
|
||||
for name, mutate in cases.items():
|
||||
with self.subTest(name):
|
||||
changed = copy.deepcopy(sidecar)
|
||||
mutate(changed)
|
||||
self.write_json(sidecar_path, changed)
|
||||
self.assertTrue(any(issue.rule == "legacy-consistency" for issue in self.validate().issues))
|
||||
|
||||
def test_builtin_skill_sidecar_must_match_the_facts_the_client_compares(self) -> None:
|
||||
self.entry_path.unlink()
|
||||
self.entry_path.with_name("SKILL.md").write_text(
|
||||
"---\nname: example-skill\ndescription: Example builtin skill.\nversion: 1.2.3\n"
|
||||
"type: meta\nrisk_level: high\ntags:\n - example\n"
|
||||
"market:\n category: development\n required_client_version: 10.0.0\n"
|
||||
"metadata:\n i18n:\n default_locale: en-US\n"
|
||||
" zh-CN:\n name: 示例技能\n short_desc: 中文简介\n"
|
||||
" en-US:\n name: Example Skill\n short_desc: English summary\n---\nBody.\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
def matching(payload):
|
||||
known_release("1.2.3", "semver")(payload)
|
||||
payload["provenance"] = {}
|
||||
payload["spec"] = {"kind": "skill", "riskLevel": "high"}
|
||||
payload["compatibility"]["requiredClientVersion"] = "10.0.0"
|
||||
|
||||
self.rewrite_sidecar(matching)
|
||||
self.assertFalse(
|
||||
any(issue.rule == "legacy-consistency" for issue in self.validate().issues),
|
||||
"an unknown frontmatter type such as meta is no skillType fact for the client",
|
||||
)
|
||||
|
||||
cases = {
|
||||
"skillType only in sidecar": lambda p: p["spec"].update(skillType="procedural"),
|
||||
"riskLevel differs": lambda p: p["spec"].update(riskLevel="low"),
|
||||
"client floor differs": lambda p: p["compatibility"].update(requiredClientVersion="10.0.1"),
|
||||
}
|
||||
for name, mutate in cases.items():
|
||||
with self.subTest(name):
|
||||
self.rewrite_sidecar(lambda p: (matching(p), mutate(p)))
|
||||
self.assertTrue(any(issue.rule == "legacy-consistency" for issue in self.validate().issues))
|
||||
|
||||
def test_agent_pointer_release_cannot_exceed_what_the_entry_declares(self) -> None:
|
||||
self.write_agent_pointer_case(lambda p: p.pop("latestVersion"))
|
||||
self.assertTrue(
|
||||
any(issue.rule == "legacy-consistency" and "release" in issue.message
|
||||
for issue in self.validate().issues)
|
||||
)
|
||||
|
||||
def test_collection_parent_version_is_ignored_like_the_client_does(self) -> None:
|
||||
def entry_change(payload):
|
||||
payload.update(latestVersion="1.2.3", children=[single_child_entry()])
|
||||
|
||||
self.write_skill_pointer_case(entry_change, add_single_child_collection)
|
||||
self.assertFalse(self.validate().has_errors)
|
||||
|
||||
def test_agent_pointer_default_policy_cannot_be_replaced_by_sidecar(self) -> None:
|
||||
def default_policy(payload):
|
||||
payload.pop("installPolicy")
|
||||
@@ -871,49 +1099,16 @@ Body.
|
||||
|
||||
def test_validates_collection_identity_and_does_not_invent_child_version(self) -> None:
|
||||
entry = valid_entry()
|
||||
entry["children"] = [
|
||||
{
|
||||
"id": "child-one",
|
||||
"path": "skills/child-one",
|
||||
"i18n": {
|
||||
"zh-CN": {"shortDesc": "Same child summary"},
|
||||
"en-US": {"shortDesc": "Same child summary"},
|
||||
},
|
||||
}
|
||||
]
|
||||
entry["children"] = [single_child_entry()]
|
||||
self.write_json(self.entry_path, entry)
|
||||
|
||||
def mutate(payload):
|
||||
child_presentation = copy.deepcopy(payload["presentation"])
|
||||
child_presentation["tags"] = []
|
||||
child_presentation["i18n"] = {
|
||||
"zh-CN": {"name": "child-one", "summary": "Same child summary"},
|
||||
"en-US": {"name": "child-one", "summary": "Same child summary"},
|
||||
}
|
||||
payload["spec"]["collection"] = {
|
||||
"role": "parent",
|
||||
"childCount": 1,
|
||||
"children": [
|
||||
{
|
||||
"identity": {
|
||||
"kind": "skill",
|
||||
"id": "child-one",
|
||||
"parentId": "example-skill",
|
||||
},
|
||||
"path": "skills/child-one",
|
||||
"presentation": child_presentation,
|
||||
"release": unknown(),
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
self.rewrite_sidecar(mutate)
|
||||
self.rewrite_sidecar(add_single_child_collection)
|
||||
report = self.validate()
|
||||
self.assertFalse(report.has_errors)
|
||||
self.assertTrue(any(issue.rule == "i18n-freshness" for issue in report.issues))
|
||||
|
||||
def invent_version(payload):
|
||||
mutate(payload)
|
||||
add_single_child_collection(payload)
|
||||
payload["spec"]["collection"]["children"][0]["release"] = {
|
||||
"state": "known",
|
||||
"version": "1.0.0",
|
||||
|
||||
@@ -32,6 +32,7 @@ from jsonschema import Draft7Validator, FormatChecker, ValidationError, validato
|
||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
SCHEMA_PATH = REPO_ROOT / "schemas" / "catalog-metadata.v1.schema.json"
|
||||
AGENT_ENTRY_SCHEMA_NAME = "market-agent-entry.client.schema.json"
|
||||
SKILL_ENTRY_SCHEMA_NAME = "market-skill-entry.client.schema.json"
|
||||
TEAM_ENTRY_SCHEMA_NAME = "market-team-entry.client.schema.json"
|
||||
# Catalog roots that may hold a sidecar, in listing order.
|
||||
CATALOG_ROOTS = ("agents", "teams", "skills")
|
||||
@@ -50,6 +51,19 @@ EXPECTED_SCHEMA_REF = "../../schemas/catalog-metadata.v1.schema.json"
|
||||
FRONTMATTER_RE = re.compile(r"^---\s*\n(.*?)\n---\s*\n", re.DOTALL)
|
||||
FULL_GIT_REF_RE = re.compile(r"^[a-fA-F0-9]{40}(?:[a-fA-F0-9]{24})?$")
|
||||
CONTAINER_DIGEST_RE = re.compile(r"^sha256:[a-fA-F0-9]{64}$")
|
||||
CLIENT_SEMVER_RE = re.compile(
|
||||
r"(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?", re.ASCII
|
||||
)
|
||||
CLIENT_CALVER_RE = re.compile(r"\d{4}(?:[.-]\d{1,2}){1,2}(?:[.-][0-9A-Za-z]+)*", re.ASCII)
|
||||
CLIENT_RISK_LEVELS = {"low", "medium", "high", "critical"}
|
||||
CLIENT_SKILL_TYPES = {"procedural", "declarative", "hybrid"}
|
||||
|
||||
|
||||
def _client_version_scheme(version: str) -> str:
|
||||
"""Classify a version the way the client's normalizeRelease does: calver wins over semver."""
|
||||
if CLIENT_CALVER_RE.fullmatch(version):
|
||||
return "calver"
|
||||
return "semver" if CLIENT_SEMVER_RE.fullmatch(version) else "opaque"
|
||||
|
||||
|
||||
def _client_pattern(validator, pattern, instance, schema):
|
||||
@@ -195,6 +209,22 @@ def _report_entry_schema_errors(
|
||||
return bool(errors)
|
||||
|
||||
|
||||
def _report_skill_collection_errors(report: Report, pointer_path: Path, root: Path, data: dict[str, Any]) -> bool:
|
||||
"""Report the two collection rules the client enforces outside its JSON Schema."""
|
||||
children = data.get("children")
|
||||
if not children:
|
||||
return False
|
||||
errors = []
|
||||
if data["source"].get("path"):
|
||||
errors.append("children and source.path are mutually exclusive")
|
||||
child_ids = [child["id"] for child in children]
|
||||
if len(child_ids) != len(set(child_ids)):
|
||||
errors.append("children must not repeat a child id")
|
||||
for error in errors:
|
||||
report.add(_rel(pointer_path, root), "skill-entry-schema", error)
|
||||
return bool(errors)
|
||||
|
||||
|
||||
def _load_team_pointer(
|
||||
sidecar: Path,
|
||||
parent: Path,
|
||||
@@ -276,6 +306,10 @@ def load_legacy(sidecar: Path, report: Report, root: Path, entry_validators: dic
|
||||
str(data["version"]) if data.get("version") is not None else None
|
||||
)
|
||||
i18n, default_locale = _legacy_i18n(data.get("i18n"), short_key="shortDesc")
|
||||
# Inline metadata may localize tags, and the client prefers the default locale's.
|
||||
localized = data.get("i18n", {}).get(default_locale) if isinstance(data.get("i18n"), dict) else None
|
||||
tags = localized.get("tags") if isinstance(localized, dict) else None
|
||||
tags = tags if tags is not None and not is_pointer else data.get("tags")
|
||||
return LegacyItem(
|
||||
kind="agent",
|
||||
item_id=parent.name,
|
||||
@@ -285,7 +319,7 @@ def load_legacy(sidecar: Path, report: Report, root: Path, entry_validators: dic
|
||||
default_locale=default_locale,
|
||||
version=version,
|
||||
category=data.get("category") if isinstance(data.get("category"), str) else None,
|
||||
tags=data.get("tags") if isinstance(data.get("tags"), list) else None,
|
||||
tags=tags if isinstance(tags, list) else None,
|
||||
)
|
||||
|
||||
if root_kind == "teams":
|
||||
@@ -313,6 +347,12 @@ def load_legacy(sidecar: Path, report: Report, root: Path, entry_validators: dic
|
||||
data = _read_json(pointer_path, report, root, "legacy-read")
|
||||
if data is None:
|
||||
return None
|
||||
if _report_entry_schema_errors(
|
||||
report, pointer_path, root, entry_validators["skill"], "skill-entry-schema", data
|
||||
) or _report_skill_collection_errors(report, pointer_path, root, data):
|
||||
return None
|
||||
if data.get("id") != parent.name:
|
||||
report.add(_rel(pointer_path, root), "legacy-consistency", "entry.id must equal the catalog directory slug")
|
||||
i18n, default_locale = _legacy_i18n(data.get("i18n"), short_key="shortDesc")
|
||||
return LegacyItem(
|
||||
kind="skill",
|
||||
@@ -321,7 +361,9 @@ def load_legacy(sidecar: Path, report: Report, root: Path, entry_validators: dic
|
||||
data=data,
|
||||
i18n=i18n,
|
||||
default_locale=default_locale,
|
||||
version=str(data["version"]) if data.get("version") is not None else None,
|
||||
# Client indexing reads latestVersion for pointers and ignores a collection
|
||||
# parent's own version, so that parent's release stays unknown.
|
||||
version=None if data.get("children") else data.get("latestVersion"),
|
||||
category=data.get("category") if isinstance(data.get("category"), str) else None,
|
||||
tags=data.get("tags") if isinstance(data.get("tags"), list) else None,
|
||||
)
|
||||
@@ -449,26 +491,59 @@ def _validate_content_consistency(
|
||||
"ref": "ref",
|
||||
"sha256": "sha256",
|
||||
}
|
||||
label = {"agent": "Agent", "team": "Team", "skill": "skill"}[legacy.kind]
|
||||
for sidecar_key, legacy_key in mapping.items():
|
||||
legacy_value = source.get(legacy_key)
|
||||
if legacy.kind in {"agent", "team"}:
|
||||
declared_value = content.get(sidecar_key)
|
||||
# A sidecar must describe the exact pointer that the client installs,
|
||||
# not add a different subdirectory or pin that entry.json never uses.
|
||||
if sidecar_key in {"path", "ref"}:
|
||||
declared_value = None if declared_value == "" else declared_value
|
||||
legacy_value = None if legacy_value == "" else legacy_value
|
||||
if declared_value != legacy_value:
|
||||
label = "Agent" if legacy.kind == "agent" else "Team"
|
||||
report.add(rel, "legacy-consistency", f"provenance.content.{sidecar_key} differs from the {label} pointer")
|
||||
elif legacy_value is not None:
|
||||
_compare(
|
||||
report,
|
||||
rel,
|
||||
f"provenance.content.{sidecar_key}",
|
||||
content.get(sidecar_key),
|
||||
legacy_value,
|
||||
)
|
||||
declared_value = content.get(sidecar_key)
|
||||
# A sidecar must describe the exact pointer that the client installs,
|
||||
# not add a different subdirectory or pin that entry.json never uses.
|
||||
if sidecar_key in {"path", "ref"}:
|
||||
declared_value = None if declared_value == "" else declared_value
|
||||
legacy_value = None if legacy_value == "" else legacy_value
|
||||
if declared_value != legacy_value:
|
||||
report.add(rel, "legacy-consistency", f"provenance.content.{sidecar_key} differs from the {label} pointer")
|
||||
|
||||
|
||||
def _validate_client_compared_facts(
|
||||
report: Report,
|
||||
rel: str,
|
||||
sidecar: dict[str, Any],
|
||||
legacy: LegacyItem,
|
||||
) -> None:
|
||||
"""Compare, both ways, the facts the client compares between a sidecar and its legacy file.
|
||||
|
||||
Any difference makes the client reject the whole sidecar, which downgrades an
|
||||
installable listing to listing-only. Clients do not hydrate Team sidecars.
|
||||
"""
|
||||
if legacy.kind == "team":
|
||||
return
|
||||
data = legacy.data
|
||||
presentation = sidecar.get("presentation", {})
|
||||
compatibility = sidecar.get("compatibility", {})
|
||||
market = data.get("market") if legacy.source_type == "builtin" and isinstance(data.get("market"), dict) else {}
|
||||
facts = [
|
||||
("presentation.category", presentation.get("category"), legacy.category),
|
||||
("presentation.tags", presentation.get("tags") or [], legacy.tags or []),
|
||||
(
|
||||
"compatibility.requiredClientVersion",
|
||||
compatibility.get("requiredClientVersion"),
|
||||
market.get("required_client_version", data.get("requiredClientVersion")),
|
||||
),
|
||||
]
|
||||
if legacy.source_type == "pointer":
|
||||
# A pointer has no compatibleAgents field for a sidecar to match.
|
||||
facts.append(("compatibility.compatibleAgents", compatibility.get("compatibleAgents") or None, None))
|
||||
if legacy.kind == "skill":
|
||||
spec = sidecar.get("spec", {})
|
||||
risk_level = data.get("riskLevel") or data.get("risk_level")
|
||||
skill_type = data.get("type")
|
||||
facts += [
|
||||
("spec.riskLevel", spec.get("riskLevel"), risk_level if risk_level in CLIENT_RISK_LEVELS else None),
|
||||
("spec.skillType", spec.get("skillType"), skill_type if skill_type in CLIENT_SKILL_TYPES else None),
|
||||
]
|
||||
for field, sidecar_value, legacy_value in facts:
|
||||
if sidecar_value != legacy_value:
|
||||
report.add(rel, "legacy-consistency", f"{field} differs from the legacy value")
|
||||
|
||||
|
||||
def _validate_governance_consistency(
|
||||
@@ -762,10 +837,11 @@ def validate_sidecar(
|
||||
if sidecar.get("$schema") not in (None, EXPECTED_SCHEMA_REF):
|
||||
report.add(rel, "fixed-sidecar-path", f"$schema must be {EXPECTED_SCHEMA_REF!r}")
|
||||
|
||||
presentation = sidecar.get("presentation", {})
|
||||
_compare(report, rel, "presentation.category", presentation.get("category"), legacy.category)
|
||||
if legacy.tags is not None:
|
||||
_compare(report, rel, "presentation.tags", presentation.get("tags"), legacy.tags)
|
||||
if legacy.kind == "team":
|
||||
presentation = sidecar.get("presentation", {})
|
||||
_compare(report, rel, "presentation.category", presentation.get("category"), legacy.category)
|
||||
if legacy.tags is not None:
|
||||
_compare(report, rel, "presentation.tags", presentation.get("tags"), legacy.tags)
|
||||
_validate_i18n(report, rel, sidecar, legacy, supported_locales)
|
||||
|
||||
release = sidecar.get("release")
|
||||
@@ -786,21 +862,26 @@ def validate_sidecar(
|
||||
"agent-policy",
|
||||
"system Agent metadata revision must not be exposed as a content release timestamp",
|
||||
)
|
||||
elif legacy.version is not None and isinstance(release, dict):
|
||||
if release.get("state") != "known":
|
||||
elif isinstance(release, dict):
|
||||
# The client derives a release from the legacy version and rejects the whole
|
||||
# sidecar when the two differ, in either direction and including the scheme.
|
||||
if legacy.version is None:
|
||||
if release.get("state") == "known":
|
||||
report.add(rel, "legacy-consistency", "release declares a version the legacy file does not have")
|
||||
elif release.get("state") != "known":
|
||||
report.add(rel, "legacy-consistency", "release must preserve the legacy version")
|
||||
else:
|
||||
_compare(report, rel, "release.version", release.get("version"), legacy.version)
|
||||
_compare(
|
||||
report, rel, "release.versionScheme",
|
||||
release.get("versionScheme"), _client_version_scheme(legacy.version),
|
||||
)
|
||||
|
||||
if legacy.kind == "agent" and legacy.source_type == "pointer":
|
||||
for field in ("installPolicy", "updatePolicy"):
|
||||
# Ordinary pointers default to market/market in the client. A sidecar
|
||||
# cannot turn an omitted pair into a system/repository listing.
|
||||
_compare(report, rel, f"spec.{field}", spec.get(field, "market"), legacy.data.get(field, "market"))
|
||||
_compare(
|
||||
report, rel, "compatibility.requiredClientVersion",
|
||||
sidecar["compatibility"].get("requiredClientVersion"), legacy.data.get("requiredClientVersion"),
|
||||
)
|
||||
|
||||
if legacy.kind == "team":
|
||||
# Teams are always fork-installed and git-pull-updated, so there is no
|
||||
@@ -813,6 +894,7 @@ def validate_sidecar(
|
||||
report.add(rel, "legacy-consistency", "compatibility.requiredClientVersion differs from the Team pointer")
|
||||
|
||||
_validate_content_consistency(report, rel, sidecar, legacy)
|
||||
_validate_client_compared_facts(report, rel, sidecar, legacy)
|
||||
_validate_governance_consistency(report, rel, sidecar, legacy)
|
||||
_validate_license_evidence(report, rel, sidecar, legacy, sidecar_path.parent)
|
||||
_validate_collection(report, rel, sidecar, legacy, supported_locales)
|
||||
@@ -966,6 +1048,7 @@ def validate_repository(root: Path = REPO_ROOT, *, require_complete: bool = Fals
|
||||
entry_validators: dict[str, Any] = {}
|
||||
for kind, schema_name, rule in (
|
||||
("agent", AGENT_ENTRY_SCHEMA_NAME, "agent-entry-schema"),
|
||||
("skill", SKILL_ENTRY_SCHEMA_NAME, "skill-entry-schema"),
|
||||
("team", TEAM_ENTRY_SCHEMA_NAME, "team-entry-schema"),
|
||||
):
|
||||
entry_schema = _read_json(root / "schemas" / schema_name, report, root, rule)
|
||||
|
||||
Reference in new issue
Block a user