Validate a _index.json file.
(index_file: Path, errors: list, warnings: list)
| 130 | |
| 131 | |
| 132 | def validate_index_file(index_file: Path, errors: list, warnings: list) -> bool: |
| 133 | """Validate a _index.json file.""" |
| 134 | try: |
| 135 | with open(index_file, "r", encoding="utf-8") as f: |
| 136 | data = json.load(f) |
| 137 | except json.JSONDecodeError as e: |
| 138 | errors.append(f" ERROR: {index_file.relative_to(ROOT)}: invalid JSON: {e}") |
| 139 | return False |
| 140 | |
| 141 | required = ["category", "last_updated", "entries"] |
| 142 | missing = [f for f in required if f not in data] |
| 143 | if missing: |
| 144 | errors.append( |
| 145 | f" ERROR: {index_file.relative_to(ROOT)}: missing fields: {', '.join(missing)}" |
| 146 | ) |
| 147 | return False |
| 148 | |
| 149 | # Validate each entry has required fields |
| 150 | for i, entry in enumerate(data.get("entries", [])): |
| 151 | entry_required = ["id", "title", "status", "source_url"] |
| 152 | entry_missing = [f for f in entry_required if f not in entry] |
| 153 | if entry_missing: |
| 154 | errors.append( |
| 155 | f" ERROR: {index_file.relative_to(ROOT)}: entry[{i}] missing: " |
| 156 | f"{', '.join(entry_missing)}" |
| 157 | ) |
| 158 | return False |
| 159 | |
| 160 | return True |
| 161 | |
| 162 | |
| 163 | def validate_path(search_path: Path, errors: list, warnings: list) -> tuple[int, int]: |