vitest.config.ts 6.2 KB

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