vitest.config.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 (v8::ToLocalChecked Empty
  60. // MaybeLocal in cjs_lexer::Parse) from worker threads on macOS
  61. // arm64 and later on Linux. A fork contains that external runtime
  62. // failure to the test process; Windows keeps the thread pool, where
  63. // the abort has not reproduced and process spawn is costlier.
  64. pool: process.platform === 'win32' ? 'threads' : 'forks',
  65. setupFiles: ['./scripts/test-invariants.ts'],
  66. include: testIncludes,
  67. exclude: [
  68. ...windowsUnsupportedPackages.map(path => `${path}/tests/**/*.spec.ts`),
  69. ...processBoundTests,
  70. ],
  71. },
  72. },
  73. {
  74. plugins: [pathsPlugin()],
  75. test: {
  76. name: 'process-bound',
  77. pool: 'forks',
  78. setupFiles: ['./scripts/test-invariants.ts'],
  79. include: processBoundTests,
  80. exclude: windowsUnsupportedPackages.map(path => `${path}/tests/**/*.spec.ts`),
  81. },
  82. },
  83. ],
  84. coverage: {
  85. provider: 'v8',
  86. // Coverage measures OUR runtime source. Types-only files carry no
  87. // executable code; vendor/ and examples/ are out of scope (examples are
  88. // exercised by the demo smoke test instead).
  89. // .tsx: client components are gated like everything else (jsdom lane).
  90. include: ['packages/*/*/src/**/*.{ts,tsx}'],
  91. // Types-only files have no runtime coverage. Importing self-executing bins/workers would boot
  92. // them inside the unit process, so real subprocess/Worker tests cover their thin entry glue.
  93. exclude: [
  94. 'packages/*/*/src/types.ts',
  95. 'packages/*/*/src/bin.ts',
  96. 'packages/*/*/src/worker.ts',
  97. // A killed executable lint-contract test can leave a non-product source probe behind.
  98. 'packages/*/*/src/oxlint-contract-*.ts',
  99. // GUI step-1 skeleton (PR #500): client/web UI files whose remaining
  100. // branches need a browser-grade harness the jsdom lane doesn't cover
  101. // yet. TODO(gui): cover and remove as the client test lane matures.
  102. 'packages/client/ui-trajectory/src/*',
  103. // Trajectory's compact Markdown projection retains deferred branch coverage.
  104. 'packages/client/ui-primitives/src/markdown/plain-text.ts',
  105. 'packages/client/ui-question/src/client/QuestionComposer.tsx',
  106. 'packages/client/ui-primitives/src/Menu.tsx',
  107. 'packages/client/ui-workspace/src/client/WorkspaceBrowser.tsx',
  108. 'packages/client/ui-workspace/src/client/WorkspacePicker.tsx',
  109. 'packages/client/web-react/src/*',
  110. 'packages/client/runtime/src/*',
  111. 'packages/client/ui-conversation/src/*',
  112. 'packages/client/ui-slots/src/*',
  113. 'packages/client/ui-layout/src/*',
  114. 'packages/client/web/src/*',
  115. 'packages/host/webserver/src/*',
  116. 'packages/client/modules/src/client/system.ts',
  117. 'packages/client/hmr/src/client/index.ts',
  118. // Web config-tree boot round: the new host-side web-transport halves
  119. // whose remaining branches need real-composition/process harnesses.
  120. // TODO(gui): cover and remove with the client test lane above.
  121. 'packages/client/modules/src/index.ts',
  122. 'packages/client/modules/src/invariant.ts',
  123. 'packages/client/modules/src/client/index.ts',
  124. 'packages/client/modules/src/client/manifest.ts',
  125. 'packages/client/hmr/src/index.ts',
  126. 'packages/client/hmr/src/invariant.ts',
  127. 'packages/client/connection/src/index.ts',
  128. 'packages/client/connection/src/http-bridge.ts',
  129. // Slash/command/input round: per-file gaps deferred with the same
  130. // client-lane debt. TODO(gui): cover and remove with the lane above.
  131. 'packages/client/connection/src/client/fixture.ts',
  132. 'packages/client/ui-command/src/index.ts',
  133. 'packages/client/ui-skill/src/index.ts',
  134. 'packages/client/ui-slash/src/index.ts',
  135. 'packages/client/ui-subagent/src/index.ts',
  136. 'packages/client/ui-command/src/client/popup.ts',
  137. 'packages/client/ui-command/src/client/directory.ts',
  138. 'packages/client/ui-command/src/client/service.ts',
  139. 'packages/client/ui-command/src/client/PopupSelectView.tsx',
  140. 'packages/client/ui-model/src/index.ts',
  141. 'packages/client/ui-permission/src/index.ts',
  142. 'packages/client/ui-model/src/client/ModelSelect.tsx',
  143. 'packages/client/ui-model/src/client/directory.ts',
  144. 'packages/client/ui-model/src/client/index.ts',
  145. 'packages/client/ui-model/src/client/service.ts',
  146. 'packages/client/ui-slash/src/client/controller.ts',
  147. 'packages/client/ui-slash/src/client/service.ts',
  148. 'packages/client/ui-slash/src/core/menu.ts',
  149. 'packages/client/ui-slash/src/core/detect.ts',
  150. 'packages/client/ui-sidebar/src/client/index.ts',
  151. 'packages/client/ui-skill/src/client/index.ts',
  152. 'packages/client/ui-workspace/src/client/index.ts',
  153. // Typert generator: correctness is pinned by its fixture suites and
  154. // the byte-for-byte catalog reproduction test; per-file coverage
  155. // would put whole-workspace compiler analysis under v8
  156. // instrumentation — the coverage lane's longest tail.
  157. 'packages/typert/generator/src/*.ts',
  158. 'packages/host/apiproxy/src/index.ts',
  159. 'packages/host/apiproxy/src/invariant.ts',
  160. 'packages/host/apiproxy/src/api-proxy.ts',
  161. // Projection/command round: executor lifecycle branches and the
  162. // registry's drive tails need the same maturing lanes. TODO(gui):
  163. // cover and remove with the client test lane above.
  164. 'packages/ui/commands/src/index.ts',
  165. 'packages/ui/commands/src/invariant.ts',
  166. 'packages/session-projection/session-projection/src/index.ts',
  167. 'packages/ui/tui/src/index.ts',
  168. ...windowsUnsupportedPackages.map(path => `${path}/src/**/*.ts`),
  169. ...windowsCoverageExclusions,
  170. ],
  171. // 100% or it doesn't merge (docs/testing.md: excessive tests are welcome).
  172. // Per-file so a well-covered big file can't subsidize a bare one.
  173. // Every v8 ignore comment must carry a reason — see the quality-gates Agent Note
  174. // (.agents/notes/implemented/process/2026-06-11-quality-gates.md).
  175. thresholds: {
  176. perFile: true,
  177. statements: 100,
  178. branches: 100,
  179. functions: 100,
  180. lines: 100,
  181. },
  182. reporter: process.env.CI ? ['text'] : ['text', 'html'],
  183. },
  184. },
  185. })