ci-workflow.spec.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 a required Wine Windows job, a non-blocking native Windows job with failover, and a master-only standby', () => {
  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['wine-apt-cache'])
  31. || !isRecord(workflow.jobs['serial-windows'])
  32. || !isRecord(workflow.jobs['all-checks-passed'])) {
  33. throw new TypeError('CI workflow must define windows, windows-native, wine-apt-cache, serial-windows, and all-checks-passed jobs')
  34. }
  35. const windows = workflow.jobs.windows
  36. const windowsNative = workflow.jobs['windows-native']
  37. const wineAptCache = workflow.jobs['wine-apt-cache']
  38. const serialWindows = workflow.jobs['serial-windows']
  39. const aggregate = workflow.jobs['all-checks-passed']
  40. if (!Array.isArray(windows.steps) || !Array.isArray(aggregate.needs)) {
  41. throw new TypeError('Windows job must define steps and the aggregate must define needs')
  42. }
  43. const commandSteps = windows.steps.filter((step): step is Record<string, unknown> & { run: string } => (
  44. isRecord(step) && typeof step.run === 'string'
  45. ))
  46. // Required PR job: Wine on ubuntu-latest, runs wine-windows-gates.sh.
  47. expect(windows['runs-on']).toBe('ubuntu-latest')
  48. expect(windows.name).toBe('windows node 24 / wine blocking')
  49. expect(windows.if).toBe("github.event_name == 'pull_request'")
  50. expect(commandSteps.some(step => step.run.includes('wine-windows-gates.sh'))).toBe(true)
  51. // windows-native: non-blocking native job with failover, runs windows-complete.
  52. expect(typeof windowsNative['runs-on']).toBe('string')
  53. expect(windowsNative['runs-on']).toContain('DSH_CI_FAILOVER')
  54. expect(windowsNative['runs-on']).toContain('self-hosted')
  55. expect(windowsNative['runs-on']).toContain('dsh-win-ci')
  56. expect(windowsNative['runs-on']).toContain('dsh-windows-2025-16core')
  57. expect(windowsNative.name).toBe('windows node 24 / native complete')
  58. expect(windowsNative.if).toBe("github.event_name == 'pull_request'")
  59. expect(windowsNative.env).toMatchObject({
  60. DSH_COVERAGE_TEST_TIMEOUT_MS: '15000',
  61. })
  62. const nativeCommandSteps = (windowsNative.steps as unknown[]).filter((step): step is Record<string, unknown> & { run: string } => (
  63. isRecord(step) && typeof step.run === 'string'
  64. ))
  65. expect(nativeCommandSteps.map(step => step.run)).toContain('pnpm run check:ci:windows-complete')
  66. // wine-apt-cache: master-only, seeds the Wine apt cache.
  67. expect(wineAptCache.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  68. expect(wineAptCache['runs-on']).toBe('ubuntu-latest')
  69. // serial-windows: master-only standby, self-hosted, non-blocking.
  70. expect(serialWindows.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  71. expect(serialWindows['runs-on']).toEqual(['self-hosted', 'dsh-win-ci', 'windows'])
  72. expect(serialWindows.name).toBe('serial / windows (self-hosted standby)')
  73. // Aggregate: Wine `windows` required, native `windows-native` excluded.
  74. expect(aggregate.needs).toContain('windows')
  75. expect(aggregate.needs).not.toContain('windows-native')
  76. expect(aggregate.needs).not.toContain('serial-windows')
  77. })
  78. it('keeps supported LSP source under native Windows coverage', () => {
  79. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  80. expect(config).not.toContain('packages/lsp/lsp-local/src/connection.ts')
  81. expect(config).not.toContain('packages/lsp/lsp-local/src/index.ts')
  82. expect(config).not.toContain('packages/lsp/lsp-local/src/instance.ts')
  83. })
  84. it('requires one release-shaped Python runtime target on every pull request', () => {
  85. const workflow = loadWorkflow('.github/workflows/ci.yml')
  86. const pythonRuntime = workflowJob(workflow, 'python-runtime')
  87. const aggregate = workflowJob(workflow, 'all-checks-passed')
  88. if (!Array.isArray(aggregate.needs)) {
  89. throw new TypeError('CI aggregate must define required job dependencies')
  90. }
  91. expect(pythonRuntime).toMatchObject({
  92. if: "github.event_name == 'pull_request'",
  93. name: 'python runtime / release-shaped Linux x64',
  94. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  95. with: {
  96. targets: 'node24-linux-x64',
  97. ci: true,
  98. },
  99. })
  100. expect(aggregate.needs).toContain('python-runtime')
  101. })
  102. it('keeps every Vitest project process-isolated on native Windows', () => {
  103. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  104. expect(config).not.toContain("pool: process.platform === 'win32' ? 'threads' : 'forks'")
  105. expect(config.match(/pool: 'forks'/g)).toHaveLength(2)
  106. })
  107. })
  108. describe('E2B e2e workflow', () => {
  109. it('is manual-only and fails loud before running the focused live suite', () => {
  110. const workflow = loadWorkflow('.github/workflows/e2b-e2e.yml')
  111. expect(workflow.on).toEqual({ workflow_dispatch: null })
  112. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs.e2b) || !Array.isArray(workflow.jobs.e2b.steps)) {
  113. throw new TypeError('E2B e2e workflow must define the e2b job steps')
  114. }
  115. const steps = workflow.jobs.e2b.steps.filter(isRecord)
  116. const preflight = steps.find(step => step.name === 'Preflight (require E2B API key)')
  117. const e2b = steps.find(step => step.name === 'E2B tests (live sandbox)')
  118. expect(preflight).toMatchObject({
  119. env: { E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}' },
  120. })
  121. expect(preflight?.run).toContain('E2B_API_KEY_EXTERNAL repository secret')
  122. expect(e2b).toMatchObject({
  123. env: {
  124. E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}',
  125. DSH_E2E_MAX_WORKERS: '1',
  126. DSH_EXAMPLE_MODE: 'lib',
  127. },
  128. })
  129. expect(e2b?.run).toContain('packages/e2b/e2b/tests/composition.e2e.ts')
  130. })
  131. })
  132. describe('Python release workflows', () => {
  133. it('keeps complete wheel validation separate from protected public publication', () => {
  134. const workflow = loadWorkflow('.github/workflows/python-release.yml')
  135. const dispatch = workflowEvent(workflow, 'workflow_dispatch')
  136. const pullRequest = workflowEvent(workflow, 'pull_request')
  137. const build = workflowJob(workflow, 'build')
  138. const pythonCompat = workflowJob(workflow, 'python-compat')
  139. const validate = workflowJob(workflow, 'validate')
  140. const publishRuntime = workflowJob(workflow, 'publish-runtime')
  141. const publishSdk = workflowJob(workflow, 'publish-sdk')
  142. if (!isRecord(dispatch.inputs)
  143. || !isRecord(dispatch.inputs.publish)
  144. || !Array.isArray(pythonCompat.steps)
  145. || !Array.isArray(validate.steps)
  146. || !Array.isArray(publishRuntime.steps)
  147. || !Array.isArray(publishSdk.steps)) {
  148. throw new TypeError('Python release workflow must define publish input and release steps')
  149. }
  150. expect(dispatch.inputs.publish).toMatchObject({ type: 'boolean', default: false })
  151. expect(pullRequest).toEqual({ types: ['labeled'] })
  152. expect(build).toMatchObject({
  153. if: "github.event_name == 'workflow_dispatch' || github.event.label.name == 'python-release-dry-run'",
  154. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  155. with: {
  156. targets: 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64',
  157. release: true,
  158. },
  159. })
  160. expect(pythonCompat.strategy).toMatchObject({ matrix: { python: ['3.10', '3.14'] } })
  161. expect(JSON.stringify(pythonCompat.steps)).toContain('deepseek-harness-sdk==${{ steps.compatibility-version.outputs.version }}')
  162. const validateSteps = JSON.stringify(validate.steps)
  163. const authorize = validate.steps.filter(isRecord).find(step => step.name === 'Authorize publication request')
  164. if (!isRecord(authorize) || typeof authorize.run !== 'string') {
  165. throw new TypeError('Python release validation must authorize publication requests')
  166. }
  167. expect(validateSteps).toContain('PUBLIC_PYPI_RELEASE_ENABLED')
  168. expect(authorize).toMatchObject({
  169. env: {
  170. PYPI_PUBLISHER_REPOSITORY: '${{ vars.PYPI_PUBLISHER_REPOSITORY }}',
  171. REPOSITORY: '${{ github.repository }}',
  172. },
  173. })
  174. expect(authorize.run).toContain('[ "$REPOSITORY" = "$PYPI_PUBLISHER_REPOSITORY" ]')
  175. expect(validateSteps).toContain('100000000')
  176. expect(publishRuntime).toMatchObject({
  177. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  178. needs: 'validate',
  179. environment: 'pypi-runtime',
  180. permissions: { contents: 'read', 'id-token': 'write' },
  181. })
  182. expect(publishSdk).toMatchObject({
  183. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  184. needs: ['validate', 'publish-runtime'],
  185. environment: 'pypi',
  186. permissions: { contents: 'read', 'id-token': 'write' },
  187. })
  188. const runtimeSteps = publishRuntime.steps.filter(isRecord)
  189. const sdkSteps = publishSdk.steps.filter(isRecord)
  190. const runtimePublish = runtimeSteps.find(step => step.name === 'Publish runtime wheels')
  191. const sdkPublish = sdkSteps.find(step => step.name === 'Publish SDK wheel')
  192. const runtimeHashes = runtimeSteps.find(step => step.name === 'Verify release artifact hashes')
  193. const sdkHashes = sdkSteps.find(step => step.name === 'Verify release artifact hashes')
  194. expect([...runtimeSteps, ...sdkSteps].some(
  195. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  196. )).toBe(false)
  197. expect([...runtimeSteps, ...sdkSteps].filter(
  198. step => step.uses === 'pypa/gh-action-pypi-publish@release/v1',
  199. )).toHaveLength(2)
  200. expect(runtimePublish).toMatchObject({
  201. with: { 'packages-dir': 'dist/runtime/', attestations: false },
  202. })
  203. expect(sdkPublish).toMatchObject({
  204. with: { 'packages-dir': 'dist/sdk/', attestations: false },
  205. })
  206. expect(runtimeHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  207. expect(sdkHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  208. })
  209. it('exposes the native wheel builder to the release caller with normalized versions', () => {
  210. const workflow = loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml')
  211. const call = workflowEvent(workflow, 'workflow_call')
  212. const plan = workflowJob(workflow, 'plan')
  213. const build = workflowJob(workflow, 'build')
  214. if (!isRecord(call.inputs) || !Array.isArray(plan.steps) || !Array.isArray(build.steps)) {
  215. throw new TypeError('Python wheel builder must define workflow_call inputs and plan steps')
  216. }
  217. const buildSteps: unknown[] = build.steps
  218. const manylinuxAddon = buildSteps.find(step => isRecord(step) && step.name === 'Rebuild Linux node-pty against manylinux 2.28')
  219. const macosCheck = buildSteps.find(step => isRecord(step) && step.name === 'Check macOS deployment target')
  220. const manylinuxSmoke = buildSteps.find(step => isRecord(step) && step.name === 'Run wheel in a manylinux 2.28 container')
  221. expect(call.inputs).toHaveProperty('targets')
  222. expect(call.inputs).toMatchObject({
  223. ci: { type: 'boolean', default: false },
  224. release: { type: 'boolean', default: false },
  225. })
  226. expect(workflow.concurrency).toMatchObject({
  227. group: 'build-single-exe-${{ github.workflow }}-${{ github.ref }}',
  228. })
  229. expect(plan.if).toContain('inputs.ci')
  230. expect(plan.if).toContain('inputs.release')
  231. expect(JSON.stringify(plan.steps)).toContain('pep440_version')
  232. expect(JSON.stringify(workflow)).toContain('macosx_14_0_arm64')
  233. expect(manylinuxAddon).toMatchObject({ if: "runner.os == 'Linux'" })
  234. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_x86_64')
  235. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_aarch64')
  236. expect(JSON.stringify(manylinuxAddon)).toContain('$HOME/setup-pnpm:$HOME/setup-pnpm:ro')
  237. expect(JSON.stringify(manylinuxAddon)).toContain('node-pty-glibc-versions.txt')
  238. expect(JSON.stringify(manylinuxAddon)).toContain('le 2.28')
  239. expect(macosCheck).toMatchObject({ if: "runner.os == 'macOS'" })
  240. expect(JSON.stringify(macosCheck)).toContain('scripts/check-macos-deployment-target.py')
  241. expect(JSON.stringify(macosCheck)).toContain('$EXE-spawn-helper')
  242. expect(manylinuxSmoke).toMatchObject({ if: "runner.os == 'Linux'" })
  243. expect(JSON.stringify(manylinuxSmoke)).toContain('-e DSH_TELEMETRY_DISABLED')
  244. })
  245. it('uses the shared macOS deployment-target check in GitLab', () => {
  246. const workflow = loadWorkflow('.gitlab-ci.yml')
  247. const runtimeWheel = workflow['.runtime-wheel']
  248. if (!isRecord(runtimeWheel) || !Array.isArray(runtimeWheel.script)) {
  249. throw new TypeError('GitLab CI must define the runtime wheel script')
  250. }
  251. const runtimeScript: unknown[] = runtimeWheel.script
  252. const macosCheck = runtimeScript.find(
  253. step => typeof step === 'string' && step.includes('PLATFORM" = macos-arm64'),
  254. )
  255. if (typeof macosCheck !== 'string') {
  256. throw new TypeError('GitLab CI must check the macOS deployment target')
  257. }
  258. expect(macosCheck).toContain('scripts/check-macos-deployment-target.py')
  259. expect(macosCheck).toContain('"$EXE" "$EXE-spawn-helper"')
  260. })
  261. })
  262. describe('Issue lifecycle workflow', () => {
  263. it('uses explicit review handoff events without rerunning when a draft becomes ready', () => {
  264. const lifecycle = loadWorkflow('.github/workflows/issue-lifecycle.yml')
  265. const lifecyclePullRequest = workflowEvent(lifecycle, 'pull_request')
  266. const lifecycleReview = workflowEvent(lifecycle, 'pull_request_review')
  267. const lifecycleJob = workflowJob(lifecycle, 'lifecycle')
  268. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  269. const policyPullRequest = workflowEvent(policy, 'pull_request')
  270. expect(lifecyclePullRequest.types).not.toContain('ready_for_review')
  271. expect(lifecyclePullRequest.types).toContain('review_requested')
  272. expect(lifecycleReview.types).toEqual(['submitted'])
  273. expect(lifecycleJob.if).toBe(
  274. "${{ github.event_name != 'pull_request_review' || (github.event.action == 'submitted' && github.event.review.state == 'changes_requested') }}",
  275. )
  276. expect(policyPullRequest.types).toContain('ready_for_review')
  277. })
  278. })
  279. describe('Git hooks', () => {
  280. it('leaves frozen Agent Note sidecars to the archive verifier', () => {
  281. const lefthook = loadWorkflow('lefthook.yml')
  282. for (const hookName of ['pre-commit', 'pre-merge-commit']) {
  283. const hook = lefthook[hookName]
  284. if (!isRecord(hook) || !Array.isArray(hook.jobs)) {
  285. throw new TypeError(`lefthook must define ${hookName} jobs`)
  286. }
  287. const pairing: unknown = hook.jobs.find(
  288. (job: unknown) => isRecord(job) && job.name === 'translation pairing (staged records)',
  289. )
  290. expect(pairing).toMatchObject({ exclude: ['.agents/notes/archived/**'] })
  291. }
  292. })
  293. })
  294. function loadWorkflow(path: string): Record<string, unknown> {
  295. const workflow: unknown = yaml.load(readFileSync(resolve(root, path), 'utf8'))
  296. if (!isRecord(workflow)) throw new TypeError(`${path} must define a workflow`)
  297. return workflow
  298. }
  299. function workflowEvent(workflow: Record<string, unknown>, event: string): Record<string, unknown> {
  300. if (!isRecord(workflow.on) || !isRecord(workflow.on[event])) {
  301. throw new TypeError(`workflow must define the ${event} event`)
  302. }
  303. return workflow.on[event]
  304. }
  305. function workflowJob(workflow: Record<string, unknown>, job: string): Record<string, unknown> {
  306. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs[job])) {
  307. throw new TypeError(`workflow must define the ${job} job`)
  308. }
  309. return workflow.jobs[job]
  310. }
  311. function isRecord(value: unknown): value is Record<string, unknown> {
  312. return typeof value === 'object' && value !== null && !Array.isArray(value)
  313. }