added
This commit is contained in:
1 parent
1e52a733d1
commit
bd8f9a641f
27 files changed
+817
-33
No files matched your search
+3
-2
@@ -20,5 +20,6 @@ python scripts/validate_repository.py . --json
|
||||
|
||||
The validator checks required paths, JSON parsing, repository-variable and
|
||||
manifest alignment, author/publisher alignment, entrypoint paths, manifest
|
||||
contents paths, version alignment, license alignment, and relative Markdown
|
||||
links. It does not prove content accuracy or check external URLs.
|
||||
contents paths, optional content-index fields and references, version alignment,
|
||||
license alignment, and relative Markdown links. It does not prove content
|
||||
accuracy or check external URLs.
|
||||
@@ -21,6 +21,7 @@ REQUIRED_PATHS = (
|
||||
"CHANGELOG.md",
|
||||
"CITATION.cff",
|
||||
"CONTRIBUTING.md",
|
||||
"content-index.json",
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"SECURITY.md",
|
||||
@@ -30,10 +31,12 @@ REQUIRED_PATHS = (
|
||||
"data/README.md",
|
||||
"docs/README.md",
|
||||
"examples/README.md",
|
||||
"examples/example-content-index.json",
|
||||
"receipts/README.md",
|
||||
"repository.json",
|
||||
"repository-variables.json",
|
||||
"schemas/README.md",
|
||||
"schemas/content-index.schema.json",
|
||||
"schemas/repository.schema.json",
|
||||
"schemas/repository-variables.schema.json",
|
||||
"scripts/README.md",
|
||||
@@ -41,6 +44,7 @@ REQUIRED_PATHS = (
|
||||
"skills/README.md",
|
||||
"skills/structure-ai-ready-repository/SKILL.md",
|
||||
"tasks/README.md",
|
||||
"templates/content-index.json.template",
|
||||
"templates/README.md",
|
||||
"templates/repository-variables.json.template",
|
||||
"tests/README.md",
|
||||
@@ -65,6 +69,24 @@ MANIFEST_REQUIRED_KEYS = (
|
||||
"ai_retrieval",
|
||||
)
|
||||
|
||||
CONTENT_INDEX_REQUIRED_KEYS = (
|
||||
"schema_version",
|
||||
"collection_id",
|
||||
"title",
|
||||
"description",
|
||||
"updated_at",
|
||||
"items",
|
||||
)
|
||||
|
||||
CONTENT_ITEM_REQUIRED_KEYS = (
|
||||
"content_id",
|
||||
"title",
|
||||
"description",
|
||||
"content_type",
|
||||
"path",
|
||||
"status",
|
||||
)
|
||||
|
||||
MARKDOWN_LINK = re.compile(r"(?<!!)\[[^\]]+\]\(([^)]+)\)")
|
||||
CITATION_VERSION = re.compile(r"(?m)^version:\s*[\"']?([^\"'\s#]+)")
|
||||
CITATION_LICENSE = re.compile(r"(?m)^license:\s*[\"']?([^\"'\s#]+)")
|
||||
@@ -121,6 +143,11 @@ def validate_manifest(root: Path, findings: list[dict[str, str]]) -> dict | None
|
||||
declared = item.get("path") if isinstance(item, dict) else None
|
||||
if not declared or not (root / declared).exists():
|
||||
add(findings, "error", f"Declared contents path does not exist: {declared}")
|
||||
declared_paths = {
|
||||
item.get("path") for item in contents if isinstance(item, dict)
|
||||
}
|
||||
if (root / "content-index.json").is_file() and "content-index.json" not in declared_paths:
|
||||
add(findings, "error", "repository.json contents must declare content-index.json")
|
||||
|
||||
retrieval = manifest.get("ai_retrieval", {})
|
||||
if isinstance(retrieval, dict):
|
||||
@@ -163,6 +190,73 @@ def validate_manifest(root: Path, findings: list[dict[str, str]]) -> dict | None
|
||||
return manifest
|
||||
|
||||
|
||||
def validate_content_index(root: Path, findings: list[dict[str, str]]) -> dict | None:
|
||||
path = root / "content-index.json"
|
||||
try:
|
||||
index = json.loads(read_text(path))
|
||||
except (OSError, UnicodeError, json.JSONDecodeError) as exc:
|
||||
add(findings, "error", f"content-index.json is invalid: {exc}")
|
||||
return None
|
||||
|
||||
for key in CONTENT_INDEX_REQUIRED_KEYS:
|
||||
if key not in index:
|
||||
add(findings, "error", f"content-index.json lacks required key: {key}")
|
||||
|
||||
items = index.get("items")
|
||||
if not isinstance(items, list):
|
||||
add(findings, "error", "content-index.json items must be an array")
|
||||
return index
|
||||
|
||||
content_ids: set[str] = set()
|
||||
paths: set[str] = set()
|
||||
related_references: list[tuple[str, str]] = []
|
||||
for position, item in enumerate(items):
|
||||
label = f"content-index.json item {position + 1}"
|
||||
if not isinstance(item, dict):
|
||||
add(findings, "error", f"{label} must be an object")
|
||||
continue
|
||||
for key in CONTENT_ITEM_REQUIRED_KEYS:
|
||||
if key not in item:
|
||||
add(findings, "error", f"{label} lacks required key: {key}")
|
||||
|
||||
content_id = item.get("content_id")
|
||||
if not isinstance(content_id, str) or not content_id:
|
||||
add(findings, "error", f"{label} has an invalid content_id")
|
||||
elif content_id in content_ids:
|
||||
add(findings, "error", f"Duplicate content_id in content-index.json: {content_id}")
|
||||
else:
|
||||
content_ids.add(content_id)
|
||||
|
||||
declared = item.get("path")
|
||||
if not isinstance(declared, str) or not declared:
|
||||
add(findings, "error", f"{label} has an invalid path")
|
||||
else:
|
||||
declared_path = Path(declared)
|
||||
if declared_path.is_absolute() or ".." in declared_path.parts:
|
||||
add(findings, "error", f"Unsafe content-index.json path: {declared}")
|
||||
elif declared in paths:
|
||||
add(findings, "error", f"Duplicate path in content-index.json: {declared}")
|
||||
else:
|
||||
paths.add(declared)
|
||||
if not (root / declared_path).is_file():
|
||||
add(findings, "error", f"Indexed content path does not exist: {declared}")
|
||||
|
||||
related = item.get("related_content_ids", [])
|
||||
if not isinstance(related, list):
|
||||
add(findings, "error", f"{label} related_content_ids must be an array")
|
||||
elif isinstance(content_id, str):
|
||||
related_references.extend((content_id, value) for value in related)
|
||||
|
||||
for source_id, related_id in related_references:
|
||||
if related_id not in content_ids:
|
||||
add(
|
||||
findings,
|
||||
"error",
|
||||
f"Unknown related_content_id in content-index.json: {source_id} -> {related_id}",
|
||||
)
|
||||
return index
|
||||
|
||||
|
||||
def validate_variables(
|
||||
root: Path, manifest: dict | None, findings: list[dict[str, str]]
|
||||
) -> dict | None:
|
||||
@@ -300,6 +394,8 @@ def validate(root: Path) -> dict:
|
||||
missing_core = False
|
||||
|
||||
manifest = None if not (root / "repository.json").is_file() else validate_manifest(root, findings)
|
||||
if (root / "content-index.json").is_file():
|
||||
validate_content_index(root, findings)
|
||||
if (root / "repository-variables.json").is_file():
|
||||
validate_variables(root, manifest, findings)
|
||||
if not missing_core:
|
||||
|
||||
Reference in new issue
Block a user