ci-workflow.spec.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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('windows-2025')
  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).not.toHaveProperty('continue-on-error')
  52. expect(nativeCommandSteps).toHaveLength(3)
  53. expect(nativeCommandSteps.every(step => step.shell === 'pwsh')).toBe(true)
  54. expect(nativeCommandSteps.map(step => step.run)).toContain('pnpm run check:ci:windows-complete')
  55. expect(JSON.stringify(windowsNative)).not.toMatch(/wine/i)
  56. expect(aggregate.needs).toContain('windows')
  57. expect(aggregate.needs).not.toContain('windows-native')
  58. })
  59. })
  60. describe('E2B e2e workflow', () => {
  61. it('is manual-only and fails loud before running the focused live suite', () => {
  62. const workflow = loadWorkflow('.github/workflows/e2b-e2e.yml')
  63. expect(workflow.on).toEqual({ workflow_dispatch: null })
  64. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs.e2b) || !Array.isArray(workflow.jobs.e2b.steps)) {
  65. throw new TypeError('E2B e2e workflow must define the e2b job steps')
  66. }
  67. const steps = workflow.jobs.e2b.steps.filter(isRecord)
  68. const preflight = steps.find(step => step.name === 'Preflight (require E2B API key)')
  69. const e2b = steps.find(step => step.name === 'E2B tests (live sandbox)')
  70. expect(preflight).toMatchObject({
  71. env: { E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}' },
  72. })
  73. expect(preflight?.run).toContain('E2B_API_KEY_EXTERNAL repository secret')
  74. expect(e2b).toMatchObject({
  75. env: {
  76. E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}',
  77. DSH_E2E_MAX_WORKERS: '1',
  78. DSH_EXAMPLE_MODE: 'lib',
  79. },
  80. })
  81. expect(e2b?.run).toContain('packages/e2b/e2b/tests/composition.e2e.ts')
  82. })
  83. })
  84. describe('Issue lifecycle workflow', () => {
  85. it('uses review signals instead of rerunning when a draft becomes ready', () => {
  86. const lifecycle = loadWorkflow('.github/workflows/issue-lifecycle.yml')
  87. const lifecyclePullRequest = workflowEvent(lifecycle, 'pull_request')
  88. const lifecycleReview = workflowEvent(lifecycle, 'pull_request_review')
  89. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  90. const policyPullRequest = workflowEvent(policy, 'pull_request')
  91. expect(lifecyclePullRequest.types).not.toContain('ready_for_review')
  92. expect(lifecyclePullRequest.types).toContain('review_requested')
  93. expect(lifecycleReview.types).toContain('submitted')
  94. expect(policyPullRequest.types).toContain('ready_for_review')
  95. })
  96. })
  97. function loadWorkflow(path: string): Record<string, unknown> {
  98. const workflow: unknown = yaml.load(readFileSync(resolve(root, path), 'utf8'))
  99. if (!isRecord(workflow)) throw new TypeError(`${path} must define a workflow`)
  100. return workflow
  101. }
  102. function workflowEvent(workflow: Record<string, unknown>, event: string): Record<string, unknown> {
  103. if (!isRecord(workflow.on) || !isRecord(workflow.on[event])) {
  104. throw new TypeError(`workflow must define the ${event} event`)
  105. }
  106. return workflow.on[event]
  107. }
  108. function isRecord(value: unknown): value is Record<string, unknown> {
  109. return typeof value === 'object' && value !== null && !Array.isArray(value)
  110. }