coverage-shards.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /** Coverage shard definitions for the GitHub Actions source-test lanes. */
  2. /** A coverage lane that owns complete package roots and optional cross-package tests. */
  3. export interface CoverageShard {
  4. /** Stable lane identifier passed through `DSH_COVERAGE_SHARD`. */
  5. name: string
  6. /** Group or package paths below `packages/` whose tests and source coverage belong to the lane. */
  7. packageRoots: readonly string[]
  8. /** Additional test roots needed for cross-package behavior or repository scripts. */
  9. extraTestRoots?: readonly string[]
  10. }
  11. /** Exhaustive, non-overlapping ownership of workspace packages in coverage CI. */
  12. export const coverageShards = [
  13. {
  14. name: 'core-loop',
  15. packageRoots: ['core/agent', 'core/agent-loop', 'core/tools'],
  16. },
  17. {
  18. name: 'state-session',
  19. packageRoots: [
  20. 'core/session',
  21. 'core/scope',
  22. 'core/system-prompt',
  23. 'context',
  24. 'session-persistence',
  25. 'session-query',
  26. 'support/invariants',
  27. ],
  28. extraTestRoots: [
  29. 'packages/examples/cli-demo/tests',
  30. 'packages/llm/token-meter/tests',
  31. 'scripts',
  32. ],
  33. },
  34. {
  35. name: 'models-integrations',
  36. packageRoots: ['llm', 'compact', 'hooks/hook-protocol', 'lsp', 'mcp', 'hooks/hooks-claude'],
  37. },
  38. {
  39. name: 'sdk-capabilities',
  40. packageRoots: [
  41. 'sdk',
  42. 'hooks/hooks-codex',
  43. 'web',
  44. 'skill',
  45. 'spill',
  46. 'util',
  47. 'guard',
  48. 'todo',
  49. 'timeout',
  50. ],
  51. },
  52. {
  53. name: 'interfaces',
  54. packageRoots: ['ui', 'examples', 'goal'],
  55. extraTestRoots: ['examples'],
  56. },
  57. { name: 'execution', packageRoots: ['fs', 'bash', 'sandbox', 'code-runtime'] },
  58. {
  59. name: 'workflow',
  60. packageRoots: ['workflow/workflow', 'workflow/tool-workflow', 'workflow/tool-ralph'],
  61. },
  62. {
  63. name: 'workflow-worker',
  64. packageRoots: ['workflow/workflow-workerthread'],
  65. },
  66. { name: 'delegation', packageRoots: ['subagent', 'tasks'] },
  67. {
  68. name: 'repository',
  69. packageRoots: [
  70. 'cordis',
  71. 'support/acp-snapshot',
  72. 'support/agent-loop-testkit',
  73. 'support/llm-replay',
  74. 'support/loader-smoke',
  75. ],
  76. },
  77. ] as const satisfies readonly CoverageShard[]
  78. /**
  79. * Build Vitest filters and coverage include globs for one source-test lane.
  80. *
  81. * @param name Stable shard name from {@link coverageShards}.
  82. * @returns Positional test roots followed by per-group coverage include flags.
  83. */
  84. export function coverageArgs(name: string): string[] {
  85. const shard = coverageShards.find(candidate => candidate.name === name)
  86. if (shard === undefined) {
  87. throw new Error(`run-gates: unknown DSH_COVERAGE_SHARD ${JSON.stringify(name)}.`)
  88. }
  89. const testRoots = new Set([
  90. ...shard.packageRoots.map(packageRoot => `packages/${packageRoot}`),
  91. ...('extraTestRoots' in shard ? shard.extraTestRoots : []),
  92. 'scripts/test-invariants.spec.ts',
  93. ])
  94. return [
  95. ...testRoots,
  96. ...shard.packageRoots.map(packageRoot => packageRoot.includes('/')
  97. ? `--coverage.include=packages/${packageRoot}/src/**/*.ts`
  98. : `--coverage.include=packages/${packageRoot}/*/src/**/*.ts`),
  99. ]
  100. }