import { expect, test } from "bun:test";
import { readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { diagnose } from "@wrnexus/syntax";

test("every shipped UI component passes compiler accessibility diagnostics", () => {
  const directory = join(import.meta.dir, "..", "components");
  const failures: string[] = [];
  const files = readdirSync(directory).filter((file) => file.endsWith(".wrn"));
  for (const file of files) {
    const diagnostics = diagnose(readFileSync(join(directory, file), "utf8"), {
      file,
      accessibility: true,
    });
    for (const diagnostic of diagnostics) {
      if (diagnostic.severity === "error" || diagnostic.code.startsWith("WRN-A11Y")) {
        failures.push(`${file}: ${diagnostic.code} ${diagnostic.message}`);
      }
    }
  }
  expect(files.length).toBeGreaterThan(100);
  expect(failures).toEqual([]);
});
