/** Performance smoke — thin routes, module size guardrails for FE-11.5 stop. */
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

const root = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
const appExp = path.join(root, "app", "experience");
const apiClient = path.join(root, "modules", "experience", "services", "experience-api.ts");

let pageCount = 0;
function walk(dir) {
  for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
    const p = path.join(dir, ent.name);
    if (ent.isDirectory()) walk(p);
    else if (ent.name === "page.tsx") pageCount += 1;
  }
}
walk(appExp);

if (pageCount < 50) {
  console.error(`expected >=50 experience pages, got ${pageCount}`);
  process.exit(1);
}

const apiSrc = fs.readFileSync(apiClient, "utf8");
if (apiSrc.includes("fake-") || apiSrc.includes("MOCK_JSON")) {
  console.error("experience-api must not ship fake frontend-only JSON fixtures");
  process.exit(1);
}
if (!apiSrc.includes("/api/experience")) {
  console.error("experience-api must call BFF /api/experience");
  process.exit(1);
}

console.log(`experience perf-smoke OK (${pageCount} routes)`);
