ci-master-platforms.spec.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /** Scheduling policy for post-merge native runtime carriers and Wine. */
  2. import { readFileSync } from 'node:fs'
  3. import { resolve } from 'node:path'
  4. import { load } from 'js-yaml'
  5. import { describe, expect, it } from 'vitest'
  6. import { gatesForMode } from '../run-gates.ts'
  7. const root = resolve(import.meta.dirname, '../..')
  8. const masterPush = "github.event_name == 'push' && github.ref == 'refs/heads/master'"
  9. const runtimeBuilder = './.github/workflows/build-exe-for-python-sdk.yml'
  10. interface Job {
  11. if?: string | boolean
  12. uses?: string
  13. needs?: string[]
  14. with?: Record<string, unknown>
  15. secrets?: Record<string, string>
  16. steps?: Array<{ name?: string; run?: string; if?: string; uses?: string; with?: Record<string, unknown> }>
  17. 'runs-on'?: string | string[]
  18. 'continue-on-error'?: boolean
  19. }
  20. interface Workflow {
  21. on: Record<string, unknown>
  22. jobs: Record<string, Job>
  23. concurrency?: Record<string, unknown>
  24. }
  25. function workflow(name: string): Workflow {
  26. return load(readFileSync(resolve(root, '.github/workflows', name), 'utf8')) as Workflow
  27. }
  28. function commands(job: Job): string[] {
  29. return (job.steps ?? []).flatMap(step => step.run ? [step.run] : [])
  30. }
  31. describe('master-only platform scheduling', () => {
  32. it('keeps only Linux and Windows x64 runtimes in required PR CI', () => {
  33. const pr = workflow('ci.yml')
  34. expect(Object.keys(pr.on)).toEqual(['pull_request'])
  35. expect(pr.jobs['python-runtime']).toMatchObject({
  36. if: "github.event_name == 'pull_request'",
  37. uses: runtimeBuilder,
  38. with: { ci: true, targets: 'node24-linux-x64,node24-win-x64' },
  39. })
  40. expect(pr.jobs.windows).toBeUndefined()
  41. expect(JSON.stringify(pr.jobs)).not.toMatch(/wine-windows-gates|check:windows-wine/)
  42. const aggregate = pr.jobs['all-checks-passed']!
  43. expect(aggregate.needs).toContain('python-runtime')
  44. expect(aggregate.needs).not.toContain('windows')
  45. expect(aggregate.needs!.every(id => id in pr.jobs)).toBe(true)
  46. expect(aggregate.if).toBe("always() && github.event_name == 'pull_request'")
  47. expect(aggregate.steps).toContainEqual(expect.objectContaining({
  48. if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped')",
  49. }))
  50. })
  51. it('runs all three deferred carriers on master pushes with fail-loud API credentials', () => {
  52. const master = workflow('ci-master.yml')
  53. expect(master.on.push).toEqual({ branches: ['master'] })
  54. expect(Object.keys(master.on).sort()).toEqual(['push', 'workflow_dispatch'])
  55. const runtime = master.jobs['python-runtime']!
  56. expect(runtime).toMatchObject({
  57. if: masterPush,
  58. uses: runtimeBuilder,
  59. with: { ci: true, targets: 'node24-linux-arm64,node24-macos-arm64,node24-macos-x64' },
  60. secrets: { DEEPSEEK_API_KEY_EXTERNAL: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}' },
  61. })
  62. expect(runtime.needs).toBeUndefined()
  63. expect(runtime['continue-on-error']).toBeUndefined()
  64. const builder = workflow('build-exe-for-python-sdk.yml')
  65. expect(builder.concurrency?.['cancel-in-progress']).toBe(
  66. "${{ github.event_name != 'push' || github.ref != 'refs/heads/master' }}",
  67. )
  68. const build = builder.jobs.build!
  69. const preflight = build.steps!.find(step => step.name === 'Preflight installed-wheel real API test (POSIX)')!
  70. expect(preflight.if).toContain('inputs.ci')
  71. expect(preflight.if).toContain("github.event_name != 'pull_request'")
  72. expect(preflight.if).toContain('github.event.pull_request.head.repo.fork')
  73. expect(preflight.if).toContain("github.event.pull_request.user.login == 'dependabot[bot]'")
  74. expect(preflight.run).toContain('exit 1')
  75. })
  76. it('runs Wine once on hosted master CI and seeds its own apt cache', () => {
  77. const master = workflow('ci-master.yml')
  78. const wine = master.jobs.windows!
  79. expect(wine).toMatchObject({ if: masterPush, 'runs-on': 'ubuntu-latest' })
  80. expect(wine.needs).toBeUndefined()
  81. expect(wine['continue-on-error']).toBeUndefined()
  82. expect(master.jobs['wine-apt-cache']).toBeUndefined()
  83. expect(Object.values(master.jobs).flatMap(commands).filter(command => command.includes('wine-windows-gates.sh')))
  84. .toEqual(['bash scripts/wine-windows-gates.sh'])
  85. expect(wine.steps).toContainEqual(expect.objectContaining({
  86. uses: 'actions/cache@v4', with: { path: '~/wine-debs', key: '${{ steps.wine-cache-key.outputs.key }}' },
  87. }))
  88. expect(commands(wine).join('\n')).toContain('--download-only wine')
  89. expect(wine.steps).toContainEqual(expect.objectContaining({ name: 'Shut down wineserver', if: 'always()' }))
  90. // Graph construction needs a pnpm entrypoint but never launches it.
  91. const previous = process.env.npm_execpath
  92. process.env.npm_execpath = '/test/pnpm.cjs'
  93. try {
  94. for (const mode of ['ci-linux-primary', 'ci-windows-complete'] as const) {
  95. expect(gatesForMode(mode).map(gate => gate.displayCommand).join('\n')).not.toMatch(/wine/i)
  96. }
  97. } finally {
  98. if (previous === undefined) Reflect.deleteProperty(process.env, 'npm_execpath')
  99. else process.env.npm_execpath = previous
  100. }
  101. expect(process.env.npm_execpath).toBe(previous)
  102. })
  103. it('retains the complete release matrix independently of CI scheduling', () => {
  104. const release = workflow('python-release.yml')
  105. const calls = Object.values(release.jobs).filter(job => job.uses === runtimeBuilder)
  106. expect(calls).toHaveLength(1)
  107. expect(calls[0]!.with).toMatchObject({
  108. release: true,
  109. targets: 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64,node24-macos-x64,node24-win-x64',
  110. })
  111. })
  112. })