vitest.config.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import tsconfigPaths from 'vite-tsconfig-paths'
  2. import { defineConfig } from 'vitest/config'
  3. // Resolution facade shared by every plugin instance below: tsconfig.base.json
  4. // has no include, which vite-tsconfig-paths treats as match-all, so its paths
  5. // map applies to every test file. paths must win over package exports so built
  6. // lib/ never loads a second module-singleton copy.
  7. const pathsPlugin = (): ReturnType<typeof tsconfigPaths> => tsconfigPaths({ projects: ['./tsconfig.base.json'] })
  8. const windowsUnsupportedPackages = process.platform === 'win32'
  9. ? [
  10. 'packages/bash/*',
  11. 'packages/hooks/*',
  12. 'packages/sandbox/sandbox-local',
  13. 'packages/sdk/create-sdk',
  14. 'packages/sdk/helper',
  15. ]
  16. : []
  17. // These files retain 100% per-file coverage on POSIX, where their process-pipe and terminal timing
  18. // tests are deterministic; Windows skips those cases and must not fail solely on their uncovered paths.
  19. const windowsCoverageExclusions = process.platform === 'win32'
  20. ? [
  21. 'packages/lsp/lsp-local/src/connection.ts',
  22. 'packages/lsp/lsp-local/src/index.ts',
  23. 'packages/lsp/lsp-local/src/instance.ts',
  24. 'packages/ui/tui/src/index.ts',
  25. ]
  26. : []
  27. const testIncludes = [
  28. 'packages/*/*/tests/**/*.spec.{ts,tsx}',
  29. 'examples/*/tests/**/*.spec.ts',
  30. 'scripts/**/*.spec.ts',
  31. ]
  32. // These suites exercise process-global state, process APIs, or timing-sensitive process I/O
  33. // that worker threads cannot isolate reliably under aggregate gate contention.
  34. // Keep the narrow exception in forks while the rest of the inventory avoids per-file processes.
  35. const processBoundTests = [
  36. 'packages/bash/bash-local/tests/run.spec.ts',
  37. 'packages/context/time-context/tests/time-context.spec.ts',
  38. 'packages/llm/llm-pi-ai/tests/adapter.spec.ts',
  39. 'packages/ui/app-boot/tests/app-boot.spec.ts',
  40. 'packages/workflow/workflow-workerthread/tests/session.spec.ts',
  41. ]
  42. export default defineConfig({
  43. plugins: [pathsPlugin()],
  44. test: {
  45. setupFiles: ['./scripts/test-invariants.ts'],
  46. // .tsx: client component specs (jsdom via per-file @vitest-environment pragma).
  47. include: testIncludes,
  48. exclude: windowsUnsupportedPackages.map(path => `${path}/tests/**/*.spec.ts`),
  49. // One coverage invocation aggregates both projects. Most suites use threads
  50. // for lower startup/IPC overhead; only explicit process-bound suites fork.
  51. projects: [
  52. {
  53. plugins: [pathsPlugin()],
  54. test: {
  55. name: 'thread-safe',
  56. pool: 'threads',
  57. setupFiles: ['./scripts/test-invariants.ts'],
  58. include: testIncludes,
  59. exclude: [
  60. ...windowsUnsupportedPackages.map(path => `${path}/tests/**/*.spec.ts`),
  61. ...processBoundTests,
  62. ],
  63. },
  64. },
  65. {
  66. plugins: [pathsPlugin()],
  67. test: {
  68. name: 'process-bound',
  69. pool: 'forks',
  70. setupFiles: ['./scripts/test-invariants.ts'],
  71. include: processBoundTests,
  72. exclude: windowsUnsupportedPackages.map(path => `${path}/tests/**/*.spec.ts`),
  73. },
  74. },
  75. ],
  76. coverage: {
  77. provider: 'v8',
  78. // Coverage measures OUR runtime source. Types-only files carry no
  79. // executable code; vendor/ and examples/ are out of scope (examples are
  80. // exercised by the demo smoke test instead).
  81. // .tsx: client components are gated like everything else (jsdom lane).
  82. include: ['packages/*/*/src/**/*.{ts,tsx}'],
  83. // Types-only files have no runtime coverage. Importing self-executing bins/workers would boot
  84. // them inside the unit process, so real subprocess/Worker tests cover their thin entry glue.
  85. exclude: [
  86. 'packages/*/*/src/types.ts',
  87. 'packages/*/*/src/bin.ts',
  88. 'packages/*/*/src/worker.ts',
  89. // GUI step-1 skeleton (PR #500): client/web UI files whose remaining
  90. // branches need a browser-grade harness the jsdom lane doesn't cover
  91. // yet. TODO(gui): cover and remove as the client test lane matures.
  92. 'packages/client/ui-trajectory/src/*',
  93. 'packages/client/ui-question/src/client/QuestionComposer.tsx',
  94. 'packages/client/web-react/src/*',
  95. 'packages/client/runtime/src/*',
  96. 'packages/client/ui-conversation/src/*',
  97. 'packages/client/ui-slots/src/*',
  98. 'packages/client/ui-layout/src/*',
  99. 'packages/client/web/src/*',
  100. 'packages/host/webserver/src/*',
  101. 'packages/client/modules/src/loader.ts',
  102. 'packages/client/hmr/src/client/index.ts',
  103. ...windowsUnsupportedPackages.map(path => `${path}/src/**/*.ts`),
  104. ...windowsCoverageExclusions,
  105. ],
  106. // 100% or it doesn't merge (docs/testing.md: excessive tests are welcome).
  107. // Per-file so a well-covered big file can't subsidize a bare one.
  108. // Every v8 ignore comment must carry a reason — see the quality-gates Agent Note
  109. // (.agents/notes/implemented/process/2026-06-11-quality-gates.md).
  110. thresholds: {
  111. perFile: true,
  112. statements: 100,
  113. branches: 100,
  114. functions: 100,
  115. lines: 100,
  116. },
  117. reporter: process.env.CI ? ['text'] : ['text', 'html'],
  118. },
  119. },
  120. })