Spaces:
Runtime error
Runtime error
| """Output directory validation.""" | |
| from __future__ import annotations | |
| from pathlib import Path | |
| # Spec paper-module files a complete module must contain. | |
| REQUIRED_FILES = [ | |
| "paper.md", | |
| "metadata.json", | |
| "sources.json", | |
| "bibtex.bib", | |
| "summary.md", | |
| "claims.md", | |
| "related_work.md", | |
| "implementation.md", | |
| "reproduction.md", | |
| "study_notes.md", | |
| "review.md", | |
| "README.md", | |
| "generation-report.md", | |
| ] | |
| def validate_paper_module(output_dir: Path) -> list[dict]: | |
| """ | |
| Check that all required spec files exist in a paper module directory. | |
| Returns list of {ok: bool, message: str} dicts. | |
| """ | |
| results = [] | |
| if not output_dir.exists(): | |
| return [{"ok": False, "message": f"Output directory does not exist: {output_dir}"}] | |
| for filename in REQUIRED_FILES: | |
| path = output_dir / filename | |
| if path.exists(): | |
| results.append({"ok": True, "message": f"{filename} exists"}) | |
| else: | |
| results.append({"ok": False, "message": f"Missing: {filename}"}) | |
| # Check metadata.json / sources.json are valid JSON | |
| for name in ("metadata.json", "sources.json"): | |
| path = output_dir / name | |
| if path.exists(): | |
| try: | |
| import json | |
| json.loads(path.read_text(encoding="utf-8")) | |
| results.append({"ok": True, "message": f"{name} is valid JSON"}) | |
| except Exception as e: | |
| results.append({"ok": False, "message": f"{name} JSON parse error: {e}"}) | |
| return results | |