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

test("production targets fail before bundling incompatible application imports", () => {
  const root = mkdtempSync(join(tmpdir(), "wrnexus-edge-build-"));
  mkdirSync(join(root, "app", "api"), { recursive: true });
  writeFileSync(join(root, "app", "api", "files.ts"), `import fs from "node:fs";`);
  expect(() => validateRuntimeCapabilities(root, "edge")).toThrow(/WRN-RUNTIME-CAPABILITY/);
  expect(() => validateRuntimeCapabilities(root, "worker")).toThrow(/filesystem/);
  expect(() => validateRuntimeCapabilities(root, "bun")).not.toThrow();
});
