import path from "node:path";
import os from "node:os";
import fs from "node:fs";
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { runSyncCheck } from "./sync-check";

describe("runSyncCheck (integration)", () => {
  let tmpDir: string;

  beforeEach(() => {
    tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "sync-check-int-"));
  });

  afterEach(() => {
    fs.rmSync(tmpDir, { recursive: true, force: true });
  });

  it("combines source sync and test case sync errors", async () => {
    const srcDir = path.join(tmpDir, "modules", "foo", "command");
    fs.mkdirSync(srcDir, { recursive: true });
    fs.writeFileSync(path.join(srcDir, "createOrder.ts"), "export {}");

    const result = await runSyncCheck({ modulesRoot: "modules" }, tmpDir);
    expect(result.exitCode).toBe(1);
    expect(result.errors.some((e) => e.type === "missing-doc")).toBe(true);
  });
});
