ci-workflow.spec.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { readFileSync } from 'node:fs'
  2. import { resolve } from 'node:path'
  3. import * as yaml from 'js-yaml'
  4. import { describe, expect, it } from 'vitest'
  5. const root = resolve(import.meta.dirname, '..')
  6. const runnerPrivatePnpmDestination = '${{ runner.temp }}/setup-pnpm'
  7. describe('CI workflow', () => {
  8. it('isolates every pnpm action setup destination per runner', () => {
  9. const workflow: unknown = yaml.load(readFileSync(resolve(root, '.github/workflows/ci.yml'), 'utf8'))
  10. if (!isRecord(workflow) || !isRecord(workflow.jobs)) throw new TypeError('CI workflow must define jobs')
  11. const setups = Object.entries(workflow.jobs).flatMap(([jobName, job]) => {
  12. if (!isRecord(job) || !Array.isArray(job.steps)) return []
  13. return job.steps.flatMap((step) => {
  14. if (!isRecord(step) || typeof step.uses !== 'string' || !step.uses.startsWith('pnpm/action-setup@')) return []
  15. return [{ jobName, step }]
  16. })
  17. })
  18. expect(setups.length).toBeGreaterThan(0)
  19. for (const { jobName, step } of setups) {
  20. expect(step, `${jobName} must not share pnpm/action-setup's default destination`).toMatchObject({
  21. with: { dest: runnerPrivatePnpmDestination },
  22. })
  23. }
  24. })
  25. it('keeps Wine blocking while native Windows reports independently', () => {
  26. const workflow = loadWorkflow('.github/workflows/ci.yml')
  27. if (!isRecord(workflow.jobs)
  28. || !isRecord(workflow.jobs.windows)
  29. || !isRecord(workflow.jobs['windows-native'])
  30. || !isRecord(workflow.jobs['all-checks-passed'])) {
  31. throw new TypeError('CI workflow must define Wine, native Windows, and aggregate jobs')
  32. }
  33. const windows = workflow.jobs.windows
  34. const windowsNative = workflow.jobs['windows-native']
  35. const aggregate = workflow.jobs['all-checks-passed']
  36. if (!Array.isArray(windows.steps) || !Array.isArray(windowsNative.steps) || !Array.isArray(aggregate.needs)) {
  37. throw new TypeError('Windows jobs must define steps and the aggregate must define needs')
  38. }
  39. const nativeCommandSteps = windowsNative.steps.filter((step): step is Record<string, unknown> & { run: string } => (
  40. isRecord(step) && typeof step.run === 'string'
  41. ))
  42. expect(windows['runs-on']).toBe('ubuntu-latest')
  43. expect(windows.name).toBe('windows node 24 / wine blocking')
  44. expect(windows.if).toBe("github.event_name == 'pull_request'")
  45. expect(JSON.stringify(windows)).toContain('bash scripts/wine-windows-gates.sh')
  46. expect(workflow.jobs).toHaveProperty('wine-apt-cache')
  47. expect(windowsNative['runs-on']).toBe('dsh-windows-2025-16core')
  48. expect(windowsNative.name).toBe('windows node 24 / native complete')
  49. expect(windowsNative['timeout-minutes']).toBe(60)
  50. expect(windowsNative.if).toBe("github.event_name == 'pull_request'")
  51. expect(windowsNative.env).toMatchObject({
  52. DSH_COVERAGE_MAX_WORKERS: '2',
  53. DSH_GATE_CONCURRENCY: '2',
  54. DSH_PUBLINT_CONCURRENCY: '8',
  55. })
  56. expect(windowsNative).not.toHaveProperty('continue-on-error')
  57. expect(nativeCommandSteps).toHaveLength(3)
  58. expect(nativeCommandSteps.every(step => step.shell === 'pwsh')).toBe(true)
  59. expect(nativeCommandSteps.map(step => step.run)).toContain('pnpm run check:ci:windows-complete')
  60. expect(JSON.stringify(windowsNative)).not.toMatch(/wine/i)
  61. expect(aggregate.needs).toContain('windows')
  62. expect(aggregate.needs).not.toContain('windows-native')
  63. })
  64. it('keeps supported LSP source under native Windows coverage', () => {
  65. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  66. expect(config).not.toContain('packages/lsp/lsp-local/src/connection.ts')
  67. expect(config).not.toContain('packages/lsp/lsp-local/src/index.ts')
  68. expect(config).not.toContain('packages/lsp/lsp-local/src/instance.ts')
  69. })
  70. it('keeps every Vitest project process-isolated on native Windows', () => {
  71. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  72. expect(config).not.toContain("pool: process.platform === 'win32' ? 'threads' : 'forks'")
  73. expect(config.match(/pool: 'forks'/g)).toHaveLength(2)
  74. })
  75. })
  76. describe('E2B e2e workflow', () => {
  77. it('is manual-only and fails loud before running the focused live suite', () => {
  78. const workflow = loadWorkflow('.github/workflows/e2b-e2e.yml')
  79. expect(workflow.on).toEqual({ workflow_dispatch: null })
  80. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs.e2b) || !Array.isArray(workflow.jobs.e2b.steps)) {
  81. throw new TypeError('E2B e2e workflow must define the e2b job steps')
  82. }
  83. const steps = workflow.jobs.e2b.steps.filter(isRecord)
  84. const preflight = steps.find(step => step.name === 'Preflight (require E2B API key)')
  85. const e2b = steps.find(step => step.name === 'E2B tests (live sandbox)')
  86. expect(preflight).toMatchObject({
  87. env: { E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}' },
  88. })
  89. expect(preflight?.run).toContain('E2B_API_KEY_EXTERNAL repository secret')
  90. expect(e2b).toMatchObject({
  91. env: {
  92. E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}',
  93. DSH_E2E_MAX_WORKERS: '1',
  94. DSH_EXAMPLE_MODE: 'lib',
  95. },
  96. })
  97. expect(e2b?.run).toContain('packages/e2b/e2b/tests/composition.e2e.ts')
  98. })
  99. })
  100. describe('Issue lifecycle workflow', () => {
  101. it('uses review signals instead of rerunning when a draft becomes ready', () => {
  102. const lifecycle = loadWorkflow('.github/workflows/issue-lifecycle.yml')
  103. const lifecyclePullRequest = workflowEvent(lifecycle, 'pull_request')
  104. const lifecycleReview = workflowEvent(lifecycle, 'pull_request_review')
  105. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  106. const policyPullRequest = workflowEvent(policy, 'pull_request')
  107. expect(lifecyclePullRequest.types).not.toContain('ready_for_review')
  108. expect(lifecyclePullRequest.types).toContain('review_requested')
  109. expect(lifecycleReview.types).toContain('submitted')
  110. expect(policyPullRequest.types).toContain('ready_for_review')
  111. })
  112. })
  113. function loadWorkflow(path: string): Record<string, unknown> {
  114. const workflow: unknown = yaml.load(readFileSync(resolve(root, path), 'utf8'))
  115. if (!isRecord(workflow)) throw new TypeError(`${path} must define a workflow`)
  116. return workflow
  117. }
  118. function workflowEvent(workflow: Record<string, unknown>, event: string): Record<string, unknown> {
  119. if (!isRecord(workflow.on) || !isRecord(workflow.on[event])) {
  120. throw new TypeError(`workflow must define the ${event} event`)
  121. }
  122. return workflow.on[event]
  123. }
  124. function isRecord(value: unknown): value is Record<string, unknown> {
  125. return typeof value === 'object' && value !== null && !Array.isArray(value)
  126. }