import path from "node:path";
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";

export default defineConfig({
  plugins: [tsconfigPaths()],
  resolve: {
    alias: {
      // Explicit absolute-path alias (tsconfigPaths also provides "@/", but
      // Vitest's Jest-style __mocks__ sibling resolution only works reliably
      // through resolve.alias — with tsconfig-paths-only aliasing it silently
      // falls back to automocking (vitest-dev/vitest#8343).
      "@": path.resolve(__dirname, "./src"),
      "@archestra/shared/access-control": path.resolve(
        __dirname,
        "../shared/access-control.ts",
      ),
      "@archestra/shared": path.resolve(__dirname, "../shared/index.ts"),
    },
  },
  test: {
    globals: true,
    include: ["./src/**/*.test.{ts,tsx}"],
    environment: "jsdom",
    setupFiles: ["./vitest-setup.ts"],
    testTimeout: 10_000,
    // JSDOM-heavy frontend tests need a larger worker heap on Node 24.
    pool: "forks",
    execArgv: ["--max-old-space-size=8192"],
    // CI runs backend and frontend tests in parallel, so keep jsdom worker pressure low.
    maxConcurrency: 2,
  },
});
