vitest.config.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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/subprocess/*',
  13. 'packages/pty/pty-local',
  14. 'packages/sandbox/sandbox-local',
  15. 'packages/sdk/create-sdk',
  16. 'packages/sdk/helper',
  17. ]
  18. : []
  19. // These files retain 100% per-file coverage on POSIX, where their process-pipe and terminal timing
  20. // tests are deterministic; Windows skips those cases and must not fail solely on their uncovered paths.
  21. const windowsCoverageExclusions = process.platform === 'win32'
  22. ? [
  23. 'packages/lsp/lsp-local/src/connection.ts',
  24. 'packages/lsp/lsp-local/src/index.ts',
  25. 'packages/lsp/lsp-local/src/instance.ts',
  26. 'packages/ui/tui/src/index.ts',
  27. ]
  28. : []
  29. const testIncludes = [
  30. 'packages/*/*/tests/**/*.spec.{ts,tsx}',
  31. 'apps/*/tests/**/*.spec.ts',
  32. 'examples/*/tests/**/*.spec.ts',
  33. 'scripts/**/*.spec.ts',
  34. ]
  35. // These suites exercise process-global state, process APIs, or timing-sensitive process I/O
  36. // that worker threads cannot isolate reliably under aggregate gate contention.
  37. // Keep the narrow exception in forks while the rest of the inventory avoids per-file processes.
  38. const processBoundTests = [
  39. 'packages/subprocess/subprocess-local/tests/spawn.spec.ts',
  40. 'packages/context/time-context/tests/time-context.spec.ts',
  41. 'packages/llm/llm-pi-ai/tests/adapter.spec.ts',
  42. 'packages/ui/app-boot/tests/app-boot.spec.ts',
  43. 'packages/workflow/workflow-workerthread/tests/session.spec.ts',
  44. ]
  45. export default defineConfig({
  46. plugins: [pathsPlugin()],
  47. test: {
  48. setupFiles: ['./scripts/test-invariants.ts'],
  49. // .tsx: client component specs (jsdom via per-file @vitest-environment pragma).
  50. include: testIncludes,
  51. exclude: windowsUnsupportedPackages.map(path => `${path}/tests/**/*.spec.ts`),
  52. // One coverage invocation aggregates both projects. Most suites use threads
  53. // for lower startup/IPC overhead; only explicit process-bound suites fork.
  54. projects: [
  55. {
  56. plugins: [pathsPlugin()],
  57. test: {
  58. name: 'thread-safe',
  59. // Node 24 has aborted in its CJS lexer from a macOS arm64 worker
  60. // thread. A fork contains that external runtime failure to the test
  61. // process; other hosts retain the lower-overhead thread pool.
  62. pool: process.platform === 'darwin' ? 'forks' : 'threads',
  63. setupFiles: ['./scripts/test-invariants.ts'],
  64. include: testIncludes,
  65. exclude: [
  66. ...windowsUnsupportedPackages.map(path => `${path}/tests/**/*.spec.ts`),
  67. ...processBoundTests,
  68. ],
  69. },
  70. },
  71. {
  72. plugins: [pathsPlugin()],
  73. test: {
  74. name: 'process-bound',
  75. pool: 'forks',
  76. setupFiles: ['./scripts/test-invariants.ts'],
  77. include: processBoundTests,
  78. exclude: windowsUnsupportedPackages.map(path => `${path}/tests/**/*.spec.ts`),
  79. },
  80. },
  81. ],
  82. coverage: {
  83. provider: 'v8',
  84. // Coverage measures OUR runtime source. Types-only files carry no
  85. // executable code; vendor/ and examples/ are out of scope (examples are
  86. // exercised by the demo smoke test instead).
  87. // .tsx: client components are gated like everything else (jsdom lane).
  88. include: ['packages/*/*/src/**/*.{ts,tsx}'],
  89. // Types-only files have no runtime coverage. Importing self-executing bins/workers would boot
  90. // them inside the unit process, so real subprocess/Worker tests cover their thin entry glue.
  91. exclude: [
  92. 'packages/*/*/src/types.ts',
  93. 'packages/*/*/src/bin.ts',
  94. 'packages/*/*/src/worker.ts',
  95. // GUI step-1 skeleton (PR #500): client/web UI files whose remaining
  96. // branches need a browser-grade harness the jsdom lane doesn't cover
  97. // yet. TODO(gui): cover and remove as the client test lane matures.
  98. 'packages/client/ui-trajectory/src/*',
  99. 'packages/client/ui-question/src/client/QuestionComposer.tsx',
  100. 'packages/client/web-react/src/*',
  101. 'packages/client/runtime/src/*',
  102. 'packages/client/ui-conversation/src/*',
  103. 'packages/client/ui-slots/src/*',
  104. 'packages/client/ui-layout/src/*',
  105. 'packages/client/web/src/*',
  106. 'packages/host/webserver/src/*',
  107. 'packages/client/modules/src/client/system.ts',
  108. 'packages/client/hmr/src/client/index.ts',
  109. // Web config-tree boot round: the new host-side web-transport halves
  110. // whose remaining branches need real-composition/process harnesses.
  111. // TODO(gui): cover and remove with the client test lane above.
  112. 'packages/client/modules/src/index.ts',
  113. 'packages/client/modules/src/invariant.ts',
  114. 'packages/client/modules/src/client/index.ts',
  115. 'packages/client/modules/src/client/manifest.ts',
  116. 'packages/client/hmr/src/index.ts',
  117. 'packages/client/hmr/src/invariant.ts',
  118. 'packages/client/connection/src/index.ts',
  119. 'packages/client/connection/src/http-bridge.ts',
  120. // Slash/command/input round: per-file gaps deferred with the same
  121. // client-lane debt. TODO(gui): cover and remove with the lane above.
  122. 'packages/client/connection/src/client/fixture.ts',
  123. 'packages/client/ui-command/src/index.ts',
  124. 'packages/client/ui-skill/src/index.ts',
  125. 'packages/client/ui-slash/src/index.ts',
  126. 'packages/client/ui-subagent/src/index.ts',
  127. 'packages/client/ui-command/src/client/popup.ts',
  128. 'packages/client/ui-command/src/client/directory.ts',
  129. 'packages/client/ui-command/src/client/service.ts',
  130. 'packages/client/ui-command/src/client/PopupSelectView.tsx',
  131. 'packages/client/ui-model/src/index.ts',
  132. 'packages/client/ui-model/src/client/ModelSelect.tsx',
  133. 'packages/client/ui-model/src/client/directory.ts',
  134. 'packages/client/ui-model/src/client/index.ts',
  135. 'packages/client/ui-model/src/client/service.ts',
  136. 'packages/client/ui-slash/src/client/controller.ts',
  137. 'packages/client/ui-slash/src/client/service.ts',
  138. 'packages/client/ui-slash/src/core/menu.ts',
  139. 'packages/client/ui-slash/src/core/detect.ts',
  140. 'packages/client/ui-sidebar/src/client/index.ts',
  141. 'packages/client/ui-skill/src/client/index.ts',
  142. 'packages/client/ui-workspace/src/client/index.ts',
  143. 'packages/host/apiproxy/src/index.ts',
  144. 'packages/host/apiproxy/src/invariant.ts',
  145. 'packages/host/apiproxy/src/api-proxy.ts',
  146. ...windowsUnsupportedPackages.map(path => `${path}/src/**/*.ts`),
  147. ...windowsCoverageExclusions,
  148. ],
  149. // 100% or it doesn't merge (docs/testing.md: excessive tests are welcome).
  150. // Per-file so a well-covered big file can't subsidize a bare one.
  151. // Every v8 ignore comment must carry a reason — see the quality-gates Agent Note
  152. // (.agents/notes/implemented/process/2026-06-11-quality-gates.md).
  153. thresholds: {
  154. perFile: true,
  155. statements: 100,
  156. branches: 100,
  157. functions: 100,
  158. lines: 100,
  159. },
  160. reporter: process.env.CI ? ['text'] : ['text', 'html'],
  161. },
  162. },
  163. })