"""Next.js BFF routes for local JSON live under periscope/src.""" from __future__ import annotations from pathlib import Path ROOT = Path(__file__).resolve().parents[1] SRC = ROOT / "periscope" / "src" / "frontend" / "src" def _text(rel: str) -> str: path = SRC / rel assert path.is_file(), rel return path.read_text(encoding="utf-8") def test_bff_routes_are_src(): for rel in ( "lib/mock-data.ts", "app/(app)/api/_project-json.ts", "app/(app)/api/projects/route.ts", "app/(app)/api/report/[id]/route.ts", "app/(app)/api/graph/[id]/route.ts", ): head = _text(rel)[:400] assert "Native Periscope overlay" not in head def test_projects_route_serves_mock_catalog(): route = _text("app/(app)/api/projects/route.ts") assert "export async function GET" in route assert "PROJECTS" in route mock = _text("lib/mock-data.ts") assert "export const PROJECTS" in mock assert "simple_project" in mock assert "export function createPipelineSteps" in mock def test_report_and_graph_read_sibling_json(): report = _text("app/(app)/api/report/[id]/route.ts") graph = _text("app/(app)/api/graph/[id]/route.ts") helper = _text("app/(app)/api/_project-json.ts") assert "report.json" in report assert "Report not found" in report assert "design_graph.json" in graph assert "Graph not found" in graph assert "jsonFromProjectFile" in helper assert "params: Promise<{ id: string }>" in report assert "params: Promise<{ id: string }>" in graph def test_proxy_stays_clerk_seam_in_dependency(): src_proxy = ROOT / "periscope" / "src" / "frontend" / "src" / "proxy.ts" dep_proxy = ROOT / "periscope" / "dependency" / "frontend" / "src" / "proxy.ts" assert not src_proxy.exists() text = dep_proxy.read_text(encoding="utf-8") assert "Open-core seam" in text assert "export function proxy" in text