vitest.config.ts 6.2 KB

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