vitest.include-session-id-in-errors.config.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import path from "node:path";
  2. import { defineConfig } from "vitest/config";
  3. /**
  4. * Include CCH session id in client errors - scoped coverage config
  5. *
  6. * 目的:
  7. * - 验证错误响应中附带 sessionId 的行为(message + header)
  8. * - 覆盖率只统计本次改动相关模块,避免引入 Next/DB/Redis 重模块
  9. * - 覆盖率阈值:>= 90%
  10. */
  11. export default defineConfig({
  12. test: {
  13. globals: true,
  14. environment: "happy-dom",
  15. setupFiles: ["./tests/setup.ts"],
  16. include: [
  17. "tests/unit/proxy/responses-session-id.test.ts",
  18. "tests/unit/proxy/proxy-handler-session-id-error.test.ts",
  19. "tests/unit/proxy/error-handler-session-id-error.test.ts",
  20. "tests/unit/proxy/chat-completions-handler-guard-pipeline.test.ts",
  21. ],
  22. exclude: ["node_modules", ".next", "dist", "build", "coverage", "tests/integration/**"],
  23. coverage: {
  24. provider: "v8",
  25. reporter: ["text", "html", "json"],
  26. reportsDirectory: "./coverage-include-session-id-in-errors",
  27. include: [
  28. "src/app/v1/_lib/proxy/error-session-id.ts",
  29. "src/app/v1/_lib/proxy-handler.ts",
  30. "src/app/v1/_lib/codex/chat-completions-handler.ts",
  31. ],
  32. exclude: ["node_modules/", "tests/", "**/*.d.ts", ".next/"],
  33. thresholds: {
  34. lines: 90,
  35. functions: 90,
  36. branches: 90,
  37. statements: 90,
  38. },
  39. },
  40. reporters: ["verbose"],
  41. isolate: true,
  42. mockReset: true,
  43. restoreMocks: true,
  44. clearMocks: true,
  45. },
  46. resolve: {
  47. alias: {
  48. "@": path.resolve(__dirname, "./src"),
  49. "server-only": path.resolve(__dirname, "./tests/server-only.mock.ts"),
  50. },
  51. },
  52. });