import { expect, test } from "bun:test";
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { inspectProject } from "../src/doctor.ts";

test("doctor reports a healthy minimal project", () => {
  const root = mkdtempSync(join(tmpdir(), "wrnexus-doctor-"));
  mkdirSync(join(root, "app", "pages"), { recursive: true });
  writeFileSync(join(root, "package.json"), JSON.stringify({ name: "app" }));
  writeFileSync(join(root, "wrnexus.config.ts"), "export default {};");
  const checks = inspectProject(root);
  expect(checks.every((check) => check.ok)).toBe(true);
});

test("doctor returns actionable missing-project checks", () => {
  const root = mkdtempSync(join(tmpdir(), "wrnexus-doctor-"));
  const checks = inspectProject(root);
  expect(checks.find((check) => check.name === "package.json")?.ok).toBe(false);
  expect(checks.find((check) => check.name === "app/pages")?.detail).toBe("Create app/pages");
});
