development
py 60 lines 1.99 KB
Raw
1 from __future__ import annotations
2
3 import json
4 from pathlib import Path
5 import sys
6
7 ROOT = Path(__file__).resolve().parents[1]
8 CONTENT_DIR = ROOT / "Klepon" / "Resources" / "Content"
9 ENTRIES_PATH = CONTENT_DIR / "guide_entries.json"
10 COLLECTIONS_PATH = CONTENT_DIR / "collections.json"
11
12
13 def fail(message: str) -> None:
14 print(f"ERROR: {message}")
15 sys.exit(1)
16
17
18 def main() -> None:
19 entries = json.loads(ENTRIES_PATH.read_text())
20 collections = json.loads(COLLECTIONS_PATH.read_text())
21
22 if not entries:
23 fail("guide_entries.json is empty")
24
25 ids = [entry["id"] for entry in entries]
26 unique_ids = set(ids)
27
28 if len(ids) != len(unique_ids):
29 duplicates = sorted({entry_id for entry_id in ids if ids.count(entry_id) > 1})
30 fail(f"duplicate entry ids: {', '.join(duplicates)}")
31
32 missing_featured = not any(entry.get("isFeatured") for entry in entries)
33 if missing_featured:
34 fail("at least one entry must be marked isFeatured=true")
35
36 for entry in entries:
37 for field in ["id", "title", "subtitle", "summary", "story"]:
38 value = entry.get(field)
39 if not isinstance(value, str) or not value.strip():
40 fail(f"entry {entry.get('id', '<unknown>')} has invalid field: {field}")
41
42 for related_id in entry.get("relatedIDs", []):
43 if related_id not in unique_ids:
44 fail(f"entry {entry['id']} references missing related id: {related_id}")
45
46 for collection in collections:
47 if not collection.get("entryIDs"):
48 fail(f"collection {collection.get('id', '<unknown>')} has no entryIDs")
49
50 for entry_id in collection["entryIDs"]:
51 if entry_id not in unique_ids:
52 fail(f"collection {collection['id']} references missing entry id: {entry_id}")
53
54 print(
55 f"Content validation passed: {len(entries)} entries, {len(collections)} collections, {sum(1 for entry in entries if entry.get('isFeatured'))} featured."
56 )
57
58
59 if __name__ == "__main__":
60 main()