import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import path from 'path';

export default defineConfig({
  plugins: [react()],
  test: {
    environment: 'jsdom',
    globals: true,
    setupFiles: [],
    // Automatically reset env-var mutations between tests so `vi.stubEnv`
    // or direct `process.env.X = ...` writes in one test do not leak into
    // the next. Many existing tests set env vars without a matching
    // afterEach restore — `unstubEnvs: true` provides the guardrail while
    // those test files are gradually migrated to vi.stubEnv.
    unstubEnvs: true,
    // Exclude Playwright specs (tests/) — they use @playwright/test, not vitest.
    // Also skip the Playwright defaults, Vitest's own build outputs, and the
    // CLI's node:test suite under cli/test/ (run separately by `npm test -w
    // @dashclaw/cli` or `cli && npm test`).
    exclude: [
      '**/node_modules/**',
      '**/dist/**',
      '**/.next/**',
      '**/tests/**',
      '**/playwright-report/**',
      '**/test-results/**',
      'cli/test/**',
      // Git worktrees may hold sibling-branch copies of the test suite with
      // their own divergent state; vitest should never walk into them.
      '.worktrees/**',
    ],
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './app'),
    },
  },
});
