ci-workflow.spec.ts 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. const nativeWindowsPnpmDestination = '${{ runner.temp }}/setup-pnpm-js'
  8. describe('CI workflow', () => {
  9. it('isolates every pnpm action setup destination per runner', () => {
  10. const files = ['.github/workflows/ci.yml', '.github/workflows/ci-master.yml']
  11. const setups: Array<{ jobName: string; step: unknown }> = []
  12. for (const file of files) {
  13. const workflow: unknown = yaml.load(readFileSync(resolve(root, file), 'utf8'))
  14. if (!isRecord(workflow) || !isRecord(workflow.jobs)) throw new TypeError(`${file} must define jobs`)
  15. for (const [jobName, job] of Object.entries(workflow.jobs)) {
  16. if (!isRecord(job) || !Array.isArray(job.steps)) continue
  17. for (const step of job.steps) {
  18. if (!isRecord(step) || typeof step.uses !== 'string' || !step.uses.startsWith('pnpm/action-setup@')) continue
  19. setups.push({ jobName, step })
  20. }
  21. }
  22. }
  23. expect(setups.length).toBeGreaterThan(0)
  24. for (const { jobName, step } of setups) {
  25. expect(step, `${jobName} must not share pnpm/action-setup's default destination`).toMatchObject({
  26. with: {
  27. dest: jobName.startsWith('windows-')
  28. ? nativeWindowsPnpmDestination
  29. : runnerPrivatePnpmDestination,
  30. },
  31. })
  32. if (jobName.startsWith('windows-')) expect(step).not.toMatchObject({ with: { standalone: true } })
  33. }
  34. })
  35. it('keeps required Wine and split native Windows jobs with failover, plus a master-only standby', () => {
  36. const workflow = loadWorkflow('.github/workflows/ci.yml')
  37. const masterWorkflow = loadWorkflow('.github/workflows/ci-master.yml')
  38. if (!isRecord(workflow.jobs)
  39. || !isRecord(workflow.jobs.windows)
  40. || !isRecord(workflow.jobs['windows-build'])
  41. || !isRecord(workflow.jobs['windows-coverage'])
  42. || !isRecord(workflow.jobs['windows-native-tests'])
  43. || !isRecord(workflow.jobs['windows-observational'])
  44. || !isRecord(workflow.jobs['node-24'])
  45. || !isRecord(workflow.jobs['node-24-coverage'])
  46. || !isRecord(workflow.jobs['node-24-consumers'])
  47. || !isRecord(workflow.jobs['all-checks-passed'])
  48. || !isRecord(masterWorkflow.jobs)
  49. || !isRecord(masterWorkflow.jobs['wine-apt-cache'])
  50. || !isRecord(masterWorkflow.jobs['serial-windows'])) {
  51. throw new TypeError('CI workflow must define windows, windows-build, windows-coverage, windows-native-tests, windows-observational, node-24, node-24-coverage, node-24-consumers, and all-checks-passed; ci-master must define wine-apt-cache and serial-windows')
  52. }
  53. const windows = workflow.jobs.windows
  54. const windowsBuild = workflow.jobs['windows-build']
  55. const windowsCoverage = workflow.jobs['windows-coverage']
  56. const windowsNativeTests = workflow.jobs['windows-native-tests']
  57. const windowsObservational = workflow.jobs['windows-observational']
  58. const wineAptCache = masterWorkflow.jobs['wine-apt-cache']
  59. const serialWindows = masterWorkflow.jobs['serial-windows']
  60. const node24 = workflow.jobs['node-24']
  61. const node24Coverage = workflow.jobs['node-24-coverage']
  62. const node24Consumers = workflow.jobs['node-24-consumers']
  63. const aggregate = workflow.jobs['all-checks-passed']
  64. if (!Array.isArray(windows.steps) || !Array.isArray(aggregate.needs)) {
  65. throw new TypeError('Windows job must define steps and the aggregate must define needs')
  66. }
  67. const commandSteps = windows.steps.filter((step): step is Record<string, unknown> & { run: string } => (
  68. isRecord(step) && typeof step.run === 'string'
  69. ))
  70. // Required PR job: Wine on ubuntu-latest, runs wine-windows-gates.sh.
  71. expect(windows['runs-on']).toBe('ubuntu-latest')
  72. expect(windows.name).toBe('windows node 24 / wine blocking')
  73. expect(windows.if).toBe("github.event_name == 'pull_request'")
  74. expect(commandSteps.some(step => step.run.includes('wine-windows-gates.sh'))).toBe(true)
  75. // The split native jobs all resolve their pool through the Windows switch.
  76. for (const [jobName, job] of [['windows-build', windowsBuild], ['windows-coverage', windowsCoverage], ['windows-native-tests', windowsNativeTests], ['windows-observational', windowsObservational]] as const) {
  77. expect(typeof job['runs-on']).toBe('string')
  78. expect(job['runs-on'], `${jobName} runs-on must use the Windows failover switch`).toContain('DSH_CI_FAILOVER_WINDOWS')
  79. expect(job['runs-on'], `${jobName} runs-on must not use the Linux failover switch`).not.toContain('DSH_CI_FAILOVER_LINUX')
  80. expect(job['runs-on']).toContain('self-hosted')
  81. expect(job['runs-on']).toContain('dsh-win-ci')
  82. expect(job['runs-on']).toContain('dsh-windows-2025-16core')
  83. expect(job.if).toBe("github.event_name == 'pull_request'")
  84. }
  85. // windows-build runs the blocking build/site pair.
  86. expect(windowsBuild.name).toBe('windows node 24 / build')
  87. const buildSteps = windowsBuild.steps as unknown[]
  88. const buildCommands = buildSteps.filter((step): step is Record<string, unknown> & { run: string } => (
  89. isRecord(step) && typeof step.run === 'string'
  90. ))
  91. expect(buildCommands.map(step => step.run)).toContain('pnpm run check:ci:windows-blocking')
  92. // windows-coverage uses the lower 4-partition profile.
  93. expect(windowsCoverage.name).toBe('windows node 24 / coverage')
  94. expect(windowsCoverage.env).toMatchObject({ DSH_COVERAGE_PARTITIONS: '4' })
  95. const coverageSteps = windowsCoverage.steps as unknown[]
  96. const coverageCommands = coverageSteps.filter((step): step is Record<string, unknown> & { run: string } => (
  97. isRecord(step) && typeof step.run === 'string'
  98. ))
  99. expect(coverageCommands.map(step => step.run)).toContain('pnpm run check:ci:coverage')
  100. // windows-native-tests runs the Windows-specific specs.
  101. expect(windowsNativeTests.name).toBe('windows node 24 / native tests')
  102. const nativeTestSteps = windowsNativeTests.steps as unknown[]
  103. const nativeTestCommands = nativeTestSteps.filter((step): step is Record<string, unknown> & { run: string } => (
  104. isRecord(step) && typeof step.run === 'string'
  105. ))
  106. expect(nativeTestCommands.map(step => step.run).join('\n')).toContain('tool-pwsh/tests/loader.spec.ts')
  107. expect(nativeTestCommands.map(step => step.run).join('\n')).toContain('workflow-worker-thread.spec.ts')
  108. // windows-observational is non-blocking.
  109. expect(windowsObservational.name).toBe('windows node 24 / observational')
  110. expect(windowsObservational['continue-on-error']).toBe(true)
  111. // wine-apt-cache: master-only, seeds the Wine apt cache, lives in ci-master.
  112. expect(wineAptCache.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  113. expect(wineAptCache['runs-on']).toBe('ubuntu-latest')
  114. // serial-windows: master-only standby, self-hosted, non-blocking, lives in ci-master.
  115. expect(serialWindows.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  116. expect(serialWindows['runs-on']).toEqual(['self-hosted', 'dsh-win-ci', 'windows'])
  117. expect(serialWindows.name).toBe('serial / windows (self-hosted standby)')
  118. // Aggregate: Wine and the three required split native jobs are needed;
  119. // observational stays out of the verdict.
  120. expect(aggregate.needs).toContain('windows')
  121. expect(aggregate.needs).toContain('windows-build')
  122. expect(aggregate.needs).toContain('windows-coverage')
  123. expect(aggregate.needs).toContain('windows-native-tests')
  124. expect(aggregate.needs).not.toContain('windows-observational')
  125. expect(aggregate.needs).not.toContain('serial-windows')
  126. // Linux failover is a separate switch: the three required Linux workers
  127. // and the verdict job resolve their pool through DSH_CI_FAILOVER_LINUX,
  128. // never the Windows switch.
  129. for (const [jobName, job] of [['node-24', node24], ['node-24-coverage', node24Coverage], ['node-24-consumers', node24Consumers]] as const) {
  130. expect(typeof job['runs-on']).toBe('string')
  131. expect(job['runs-on'], `${jobName} runs-on must use the Linux failover switch`).toContain('DSH_CI_FAILOVER_LINUX')
  132. expect(job['runs-on'], `${jobName} runs-on must not use the Windows failover switch`).not.toContain('DSH_CI_FAILOVER_WINDOWS')
  133. expect(job['runs-on']).toContain('vm-backup')
  134. }
  135. expect(aggregate['runs-on']).toContain('DSH_CI_FAILOVER_LINUX')
  136. expect(aggregate['runs-on']).not.toContain('DSH_CI_FAILOVER_WINDOWS')
  137. expect(aggregate['runs-on']).toContain('vm-backup')
  138. })
  139. it('gives the Wine Host TypeScript compile the repository heap budget', () => {
  140. const wineGates = readFileSync(resolve(root, 'scripts/wine-windows-gates.sh'), 'utf8')
  141. expect(wineGates).toContain(
  142. 'wine_node "$scratch/logs/host-tsc.log" --max-old-space-size=4096 "$tsc_js" -b tsconfig.host.json --pretty false',
  143. )
  144. })
  145. it('exempts push from cancellation in ci-master, so one master merge does not cancel the running drill', () => {
  146. const workflow = loadWorkflow('.github/workflows/ci-master.yml')
  147. const prWorkflow = loadWorkflow('.github/workflows/ci.yml')
  148. if (!isRecord(workflow.jobs) || !isRecord(workflow.concurrency)) {
  149. throw new TypeError('ci-master workflow must define jobs and a workflow-level concurrency block')
  150. }
  151. if (!isRecord(prWorkflow.jobs)) {
  152. throw new TypeError('ci workflow must define jobs')
  153. }
  154. // Cancellation applies to the whole superseded RUN, so this has to be
  155. // decided at workflow level and gated on the event: a job-level group
  156. // cannot exempt its job from its run being cancelled. Only push is exempt —
  157. // a drill takes longer than the interval between master merges. The negated
  158. // form is load-bearing: `== 'pull_request'` would also stop cancelling
  159. // workflow_dispatch, and a re-dispatched runner benchmark holds up to 12
  160. // larger runners for 15 minutes in this same group on master.
  161. expect(workflow.concurrency['cancel-in-progress']).toBe("${{ github.event_name != 'push' }}")
  162. // The PR-only ci.yml still cancels a superseded run on a new push, so a
  163. // fresh head does not stack a second full 9-job run behind a stale one.
  164. // Unlike ci-master it has no push carve-out: every PR event supersedes.
  165. expect(prWorkflow.concurrency).toMatchObject({
  166. 'cancel-in-progress': true,
  167. })
  168. // The exact event sets are what keep master-only jobs out of the PR check
  169. // panel: ci-master triggers only on push(master) + workflow_dispatch and
  170. // never on pull_request; ci.yml is exactly pull_request-only. Assert the
  171. // full sets so losing the wrong event, or gaining an extra one, fails.
  172. if (!isRecord(workflow.on) || !isRecord(prWorkflow.on)) {
  173. throw new TypeError('both CI workflows must define on')
  174. }
  175. expect(Object.keys(workflow.on).sort()).toEqual(['push', 'workflow_dispatch'])
  176. expect(Object.keys(prWorkflow.on)).toEqual(['pull_request'])
  177. // Neither drill may carry a job-level group: it would not exempt the job
  178. // from run-scoped cancellation.
  179. for (const name of ['serial-linux-selfhosted', 'serial-windows']) {
  180. const job = workflow.jobs[name]
  181. if (!isRecord(job)) throw new TypeError(`${name} must be defined`)
  182. expect(job.concurrency).toBeUndefined()
  183. // Both stay master-push-only; that is what makes the push carve-out safe.
  184. expect(job.if).toBe("github.event_name == 'push' && github.ref == 'refs/heads/master'")
  185. }
  186. // What bounds the cost of exempting push: a master push may only carry the
  187. // cache seeder and the two drills. Any job reachable on push would start
  188. // accumulating uncancelled runs, so the set is pinned here.
  189. const NOT_PUSH_REACHABLE = new Set([
  190. "github.event_name == 'workflow_dispatch' && inputs.suite == 'larger-runner-benchmark'",
  191. "github.event_name == 'workflow_dispatch' && inputs.suite == 'consolidated-runner-benchmark'",
  192. ])
  193. const pushReachable = Object.entries(workflow.jobs)
  194. .filter(([, job]) => {
  195. if (!isRecord(job)) return false
  196. if (job.if === undefined) return true // unconditional: runs on every event
  197. if (job.if === false) return false // `if: false` parses as a boolean
  198. if (typeof job.if !== 'string') return true // unrecognized shape: surface it
  199. return !NOT_PUSH_REACHABLE.has(job.if.trim())
  200. })
  201. .map(([name]) => name)
  202. .sort()
  203. expect(pushReachable).toEqual(['serial-linux-selfhosted', 'serial-windows', 'wine-apt-cache'])
  204. // Why workflow_dispatch must keep cancelling: each benchmark fans out to a
  205. // dozen larger runners at once, in this same group on master. If it stopped
  206. // cancelling, a re-dispatch would queue ahead of a drill instead of
  207. // replacing the stale measurement.
  208. for (const name of ['larger-runner-benchmark', 'consolidated-runner-benchmark']) {
  209. const job = workflow.jobs[name]
  210. if (!isRecord(job) || !isRecord(job.strategy)) {
  211. throw new TypeError(`${name} must define a matrix strategy`)
  212. }
  213. expect(job.strategy['max-parallel']).toBe(12)
  214. expect(job['timeout-minutes']).toBe(15)
  215. }
  216. })
  217. it('keeps supported LSP source under native Windows coverage', () => {
  218. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  219. expect(config).not.toContain('packages/lsp/lsp-stdio/src/connection.ts')
  220. expect(config).not.toContain('packages/lsp/lsp-stdio/src/index.ts')
  221. expect(config).not.toContain('packages/lsp/lsp-stdio/src/instance.ts')
  222. })
  223. it('requires release-shaped Python runtime validation on every published target', () => {
  224. const workflow = loadWorkflow('.github/workflows/ci.yml')
  225. const pythonRuntime = workflowJob(workflow, 'python-runtime')
  226. const aggregate = workflowJob(workflow, 'all-checks-passed')
  227. if (!Array.isArray(aggregate.needs)) {
  228. throw new TypeError('CI aggregate must define required job dependencies')
  229. }
  230. expect(pythonRuntime).toMatchObject({
  231. if: "github.event_name == 'pull_request'",
  232. name: 'python runtime / release-shaped matrix',
  233. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  234. with: {
  235. targets: 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64,node24-win-x64',
  236. ci: true,
  237. },
  238. secrets: {
  239. DEEPSEEK_API_KEY_EXTERNAL: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}',
  240. },
  241. })
  242. expect(aggregate.needs).toContain('python-runtime')
  243. })
  244. it('keeps every Vitest project process-isolated on native Windows', () => {
  245. const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
  246. expect(config).not.toContain("pool: process.platform === 'win32' ? 'threads' : 'forks'")
  247. expect(config.match(/pool: 'forks'/g)).toHaveLength(2)
  248. })
  249. })
  250. describe('DeepSeek e2e workflow', () => {
  251. it('prepares bubblewrap from the pinned payload without a package transaction', () => {
  252. const workflow = loadWorkflow('.github/workflows/e2e.yml')
  253. const e2e = workflowJob(workflow, 'e2e')
  254. if (!Array.isArray(e2e.steps)) throw new TypeError('DeepSeek e2e workflow must define steps')
  255. const steps = e2e.steps.filter(isRecord)
  256. expect(steps.find(step => step.name === 'Prepare bubblewrap (unrestrict userns)')).toMatchObject({
  257. run: 'bash scripts/prepare-ci-bubblewrap.sh',
  258. })
  259. expect(JSON.stringify(steps)).not.toContain('apt-get')
  260. })
  261. it('bounds profile subprocess fan-out to the tested e2e default', () => {
  262. const workflow = loadWorkflow('.github/workflows/e2e.yml')
  263. const e2e = workflowJob(workflow, 'e2e')
  264. if (!Array.isArray(e2e.steps)) throw new TypeError('DeepSeek e2e workflow must define steps')
  265. const step = e2e.steps.filter(isRecord).find(candidate => candidate.name === 'E2E tests (real DeepSeek API)')
  266. expect(step).toMatchObject({ env: { DSH_E2E_MAX_WORKERS: 4 } })
  267. })
  268. })
  269. describe('E2B e2e workflow', () => {
  270. it('is manual-only and fails loud before running the focused live suite', () => {
  271. const workflow = loadWorkflow('.github/workflows/e2b-e2e.yml')
  272. expect(workflow.on).toEqual({ workflow_dispatch: null })
  273. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs.e2b) || !Array.isArray(workflow.jobs.e2b.steps)) {
  274. throw new TypeError('E2B e2e workflow must define the e2b job steps')
  275. }
  276. const steps = workflow.jobs.e2b.steps.filter(isRecord)
  277. const preflight = steps.find(step => step.name === 'Preflight (require E2B API key)')
  278. const e2b = steps.find(step => step.name === 'E2B tests (live sandbox)')
  279. expect(preflight).toMatchObject({
  280. env: { E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}' },
  281. })
  282. expect(preflight?.run).toContain('E2B_API_KEY_EXTERNAL repository secret')
  283. expect(e2b).toMatchObject({
  284. env: {
  285. E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}',
  286. DSH_E2E_MAX_WORKERS: '1',
  287. DSH_EXAMPLE_MODE: 'lib',
  288. },
  289. })
  290. expect(e2b?.run).toContain('packages/e2b/e2b/tests/composition.e2e.ts')
  291. })
  292. })
  293. describe('Python release workflows', () => {
  294. it('keeps complete wheel validation separate from protected public publication', () => {
  295. const workflow = loadWorkflow('.github/workflows/python-release.yml')
  296. const dispatch = workflowEvent(workflow, 'workflow_dispatch')
  297. const build = workflowJob(workflow, 'build')
  298. const pythonCompat = workflowJob(workflow, 'python-compat')
  299. const validate = workflowJob(workflow, 'validate')
  300. const publishRuntime = workflowJob(workflow, 'publish-runtime')
  301. const publishSdk = workflowJob(workflow, 'publish-sdk')
  302. if (!isRecord(dispatch.inputs)
  303. || !isRecord(dispatch.inputs.publish)
  304. || !Array.isArray(pythonCompat.steps)
  305. || !Array.isArray(validate.steps)
  306. || !Array.isArray(publishRuntime.steps)
  307. || !Array.isArray(publishSdk.steps)) {
  308. throw new TypeError('Python release workflow must define publish input and release steps')
  309. }
  310. expect(dispatch.inputs.publish).toMatchObject({ type: 'boolean', default: false })
  311. if (!isRecord(workflow.on)) throw new TypeError('python-release workflow must define on')
  312. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  313. expect(build).toMatchObject({
  314. uses: './.github/workflows/build-exe-for-python-sdk.yml',
  315. with: {
  316. targets: 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64,node24-win-x64',
  317. release: true,
  318. },
  319. })
  320. expect(pythonCompat.strategy).toMatchObject({ matrix: { python: ['3.10', '3.14'] } })
  321. const pythonCompatSteps = JSON.stringify(pythonCompat.steps)
  322. expect(pythonCompatSteps).toContain('dist/deepseek_harness_sdk-$VERSION-py3-none-any.whl')
  323. expect(pythonCompatSteps).toContain('dist/deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl')
  324. expect(pythonCompatSteps).not.toContain('--find-links')
  325. const validateSteps = JSON.stringify(validate.steps)
  326. const authorize = validate.steps.filter(isRecord).find(step => step.name === 'Authorize publication request')
  327. if (!isRecord(authorize) || typeof authorize.run !== 'string') {
  328. throw new TypeError('Python release validation must authorize publication requests')
  329. }
  330. expect(validateSteps).toContain('PUBLIC_PYPI_RELEASE_ENABLED')
  331. expect(authorize).toMatchObject({
  332. env: {
  333. PYPI_PUBLISHER_REPOSITORY: '${{ vars.PYPI_PUBLISHER_REPOSITORY }}',
  334. REPOSITORY: '${{ github.repository }}',
  335. },
  336. })
  337. expect(authorize.run).toContain('[ "$REPOSITORY" = "$PYPI_PUBLISHER_REPOSITORY" ]')
  338. expect(validateSteps).toContain('100000000')
  339. expect(publishRuntime).toMatchObject({
  340. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  341. needs: 'validate',
  342. environment: 'pypi-runtime',
  343. permissions: { contents: 'read', 'id-token': 'write' },
  344. })
  345. expect(publishSdk).toMatchObject({
  346. if: "github.event_name == 'workflow_dispatch' && inputs.publish",
  347. needs: ['validate', 'publish-runtime'],
  348. environment: 'pypi',
  349. permissions: { contents: 'read', 'id-token': 'write' },
  350. })
  351. const runtimeSteps = publishRuntime.steps.filter(isRecord)
  352. const sdkSteps = publishSdk.steps.filter(isRecord)
  353. const runtimePublish = runtimeSteps.find(step => step.name === 'Publish runtime wheels')
  354. const sdkPublish = sdkSteps.find(step => step.name === 'Publish SDK wheel')
  355. const runtimeHashes = runtimeSteps.find(step => step.name === 'Verify release artifact hashes')
  356. const sdkHashes = sdkSteps.find(step => step.name === 'Verify release artifact hashes')
  357. expect([...runtimeSteps, ...sdkSteps].some(
  358. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  359. )).toBe(false)
  360. expect([...runtimeSteps, ...sdkSteps].filter(
  361. step => step.uses === 'pypa/gh-action-pypi-publish@release/v1',
  362. )).toHaveLength(2)
  363. expect(runtimePublish).toMatchObject({
  364. with: { 'packages-dir': 'dist/runtime/', attestations: false },
  365. })
  366. expect(sdkPublish).toMatchObject({
  367. with: { 'packages-dir': 'dist/sdk/', attestations: false },
  368. })
  369. expect(runtimeHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  370. expect(sdkHashes).toMatchObject({ run: 'cd dist && sha256sum -c SHA256SUMS' })
  371. })
  372. it('exposes the native wheel builder to the release caller with normalized versions', () => {
  373. const workflow = loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml')
  374. const call = workflowEvent(workflow, 'workflow_call')
  375. const plan = workflowJob(workflow, 'plan')
  376. const build = workflowJob(workflow, 'build')
  377. if (!isRecord(call.inputs) || !isRecord(call.secrets) || !Array.isArray(plan.steps) || !Array.isArray(build.steps)) {
  378. throw new TypeError('Python wheel builder must define workflow_call inputs and plan steps')
  379. }
  380. const buildSteps: unknown[] = build.steps
  381. const manylinuxAddon = buildSteps.find(step => isRecord(step) && step.name === 'Rebuild Linux node-pty against manylinux 2.28')
  382. const macosCheck = buildSteps.find(step => isRecord(step) && step.name === 'Check macOS deployment target')
  383. const manylinuxSmoke = buildSteps.find(step => isRecord(step) && step.name === 'Run wheel in a manylinux 2.28 container')
  384. const cleanVenvPosix = buildSteps.find(step => isRecord(step) && step.name === 'Install local SDK and runtime wheels into a clean venv (POSIX)')
  385. const cleanVenvWindows = buildSteps.find(step => isRecord(step) && step.name === 'Install local SDK and runtime wheels into a clean venv (Windows)')
  386. const installedKeylessPosix = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel keyless black-box tests (POSIX)')
  387. const installedKeylessWindows = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel keyless black-box tests (Windows)')
  388. const realApiPreflightPosix = buildSteps.find(step => isRecord(step) && step.name === 'Preflight installed-wheel real API test (POSIX)')
  389. const realApiPreflightWindows = buildSteps.find(step => isRecord(step) && step.name === 'Preflight installed-wheel real API test (Windows)')
  390. const installedRealApiPosix = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel real API black-box test (POSIX)')
  391. const installedRealApiWindows = buildSteps.find(step => isRecord(step) && step.name === 'Run installed-wheel real API black-box test (Windows)')
  392. if (!isRecord(cleanVenvPosix) || !isRecord(cleanVenvWindows)
  393. || !isRecord(installedKeylessPosix) || !isRecord(installedKeylessWindows)
  394. || !isRecord(realApiPreflightPosix) || !isRecord(realApiPreflightWindows)
  395. || !isRecord(installedRealApiPosix) || !isRecord(installedRealApiWindows)) {
  396. throw new TypeError('Python wheel builder must define native POSIX and Windows installed-wheel steps')
  397. }
  398. expect(call.inputs).toHaveProperty('targets')
  399. expect(call.inputs).toMatchObject({
  400. ci: { type: 'boolean', default: false },
  401. release: { type: 'boolean', default: false },
  402. })
  403. expect(call.secrets).toMatchObject({
  404. DEEPSEEK_API_KEY_EXTERNAL: { required: false },
  405. })
  406. expect(workflow.concurrency).toMatchObject({
  407. group: 'build-single-exe-${{ github.workflow }}-${{ github.ref }}',
  408. })
  409. expect(build.defaults).toBeUndefined()
  410. expect(plan.if).toContain('inputs.ci')
  411. expect(plan.if).toContain('inputs.release')
  412. expect(JSON.stringify(plan.steps)).toContain('pep440_version')
  413. const workflowJson = JSON.stringify(workflow)
  414. expect(workflowJson).toContain('macosx_14_0_arm64')
  415. expect(workflowJson).toContain('win_amd64')
  416. expect(workflowJson).toContain('node24-win-x64')
  417. expect(workflowJson).toContain('windows-2025')
  418. expect(workflowJson).toContain('dist-python/$SDK_WHEEL')
  419. expect(workflowJson).toContain('dist-python/$RUNTIME_WHEEL')
  420. expect(workflowJson).toContain('/work/dist-python/$SDK_WHEEL')
  421. expect(workflowJson).toContain('/work/dist-python/$RUNTIME_WHEEL')
  422. expect(workflowJson).not.toContain('--find-links dist-python')
  423. expect(workflowJson).not.toContain('--find-links /work/dist-python')
  424. expect(workflowJson).not.toContain('cygpath')
  425. expect(manylinuxAddon).toMatchObject({ if: "runner.os == 'Linux'" })
  426. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_x86_64')
  427. expect(JSON.stringify(manylinuxAddon)).toContain('manylinux_2_28_aarch64')
  428. expect(JSON.stringify(manylinuxAddon)).toContain('npm_config_build_from_source=true pnpm run install')
  429. expect(JSON.stringify(manylinuxAddon)).toContain('pnpm_setup_root')
  430. expect(JSON.stringify(manylinuxAddon)).toContain('$pnpm_setup_root:$pnpm_setup_root:ro')
  431. expect(JSON.stringify(manylinuxAddon)).toContain('node-pty-glibc-versions.txt')
  432. expect(JSON.stringify(manylinuxAddon)).toContain('le 2.28')
  433. expect(macosCheck).toMatchObject({ if: "runner.os == 'macOS'" })
  434. expect(JSON.stringify(macosCheck)).toContain('scripts/check-macos-deployment-target.py')
  435. expect(JSON.stringify(macosCheck)).toContain('$EXE-spawn-helper')
  436. expect(JSON.stringify(installedKeylessPosix)).toContain('--scenario all')
  437. expect(JSON.stringify(installedKeylessPosix)).toContain('env -u PYTHONPATH')
  438. expect(JSON.stringify(installedKeylessWindows)).toContain('--scenario all --installed-wheel')
  439. expect(installedKeylessWindows).toMatchObject({ if: "runner.os == 'Windows'", shell: 'pwsh' })
  440. expect(cleanVenvWindows).toMatchObject({ if: "runner.os == 'Windows'", shell: 'pwsh' })
  441. expect(JSON.stringify(cleanVenvWindows)).toContain('Scripts\\\\python.exe')
  442. expect(realApiPreflightPosix).toMatchObject({
  443. env: { DEEPSEEK_API_KEY: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}' },
  444. })
  445. expect(String(realApiPreflightPosix.if)).toContain('inputs.ci')
  446. expect(String(realApiPreflightPosix.if)).toContain('head.repo.fork')
  447. expect(String(realApiPreflightPosix.if)).toContain('dependabot[bot]')
  448. expect(realApiPreflightWindows).toMatchObject({ shell: 'pwsh' })
  449. expect(installedRealApiPosix).toMatchObject({
  450. env: {
  451. DEEPSEEK_API_KEY: '${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}',
  452. DEEPSEEK_BASE_URL: 'https://api.deepseek.com',
  453. },
  454. })
  455. expect(JSON.stringify(installedRealApiPosix)).toContain('--scenario sdk-live')
  456. expect(JSON.stringify(installedRealApiPosix)).toContain('-u DSH_RUNTIME_MODE')
  457. expect(installedRealApiWindows).toMatchObject({ shell: 'pwsh' })
  458. expect(JSON.stringify(installedRealApiWindows)).toContain('--scenario sdk-live --installed-wheel')
  459. expect(manylinuxSmoke).toMatchObject({ if: "runner.os == 'Linux'" })
  460. expect(JSON.stringify(manylinuxSmoke)).toContain('-e DSH_TELEMETRY_DISABLED')
  461. })
  462. it('uses the shared macOS deployment-target check in GitLab', () => {
  463. const workflow = loadWorkflow('.gitlab-ci.yml')
  464. const runtimeWheel = workflow['.runtime-wheel']
  465. if (!isRecord(runtimeWheel) || !Array.isArray(runtimeWheel.script)) {
  466. throw new TypeError('GitLab CI must define the runtime wheel script')
  467. }
  468. const runtimeScript: unknown[] = runtimeWheel.script
  469. const macosCheck = runtimeScript.find(
  470. step => typeof step === 'string' && step.includes('PLATFORM" = macos-arm64'),
  471. )
  472. if (typeof macosCheck !== 'string') {
  473. throw new TypeError('GitLab CI must check the macOS deployment target')
  474. }
  475. expect(macosCheck).toContain('scripts/check-macos-deployment-target.py')
  476. expect(macosCheck).toContain('"$EXE" "$EXE-spawn-helper"')
  477. })
  478. it('builds and black-box tests the Windows x64 wheel in GitLab', () => {
  479. const workflow = loadWorkflow('.gitlab-ci.yml')
  480. const windows = workflow['runtime-windows-x64']
  481. const publish = workflow['publish-python']
  482. if (!isRecord(windows) || !Array.isArray(windows.before_script) || !Array.isArray(windows.script)
  483. || !isRecord(publish) || !Array.isArray(publish.needs)) {
  484. throw new TypeError('GitLab CI must define the Windows runtime and aggregate publication jobs')
  485. }
  486. expect(windows.tags).toEqual(['windows-x64'])
  487. expect(windows.variables).toMatchObject({ PKG_TARGET: 'node24-win-x64', PLATFORM: 'win-x64' })
  488. expect(JSON.stringify(windows.before_script)).toContain('.ci-python\\\\Scripts')
  489. expect(JSON.stringify(windows.before_script)).toContain('[IO.Path]::PathSeparator')
  490. expect(JSON.stringify(windows.script)).toContain('win_amd64.whl')
  491. expect(JSON.stringify(windows.script)).toContain('--scenario all --installed-wheel')
  492. expect(publish.needs).toContainEqual({ job: 'runtime-windows-x64', artifacts: true })
  493. })
  494. })
  495. describe('Issue lifecycle workflow', () => {
  496. it('runs the lifecycle job on every PR/review event but gates token and board steps', () => {
  497. const lifecycle = loadWorkflow('.github/workflows/issue-lifecycle.yml')
  498. const policy = loadWorkflow('.github/workflows/issue-policy.yml')
  499. const lifecycleJob = workflowJob(lifecycle, 'lifecycle')
  500. if (!Array.isArray(lifecycleJob.steps)) throw new TypeError('Issue lifecycle job must define steps')
  501. // The job has no job-level `if`, so it is listed on every pull_request /
  502. // pull_request_review event and reports success instead of a gray skip. The
  503. // write-capable steps are gated at step level so approved/commented reviews
  504. // never mint a Project/Issue App token nor touch the board.
  505. expect(lifecycle.on).toHaveProperty('pull_request')
  506. expect(lifecycle.on).toHaveProperty('pull_request_review')
  507. expect(lifecycleJob.if).toBeUndefined()
  508. // Keep the subscription-type gates: issue-lifecycle does not re-subscribe
  509. // ready_for_review (issue-policy owns that) and only reacts to submitted
  510. // review events.
  511. const lifecyclePullRequest = workflowEvent(lifecycle, 'pull_request')
  512. const lifecycleReview = workflowEvent(lifecycle, 'pull_request_review')
  513. expect(lifecyclePullRequest.types).not.toContain('ready_for_review')
  514. expect(lifecyclePullRequest.types).toContain('review_requested')
  515. expect(lifecycleReview.types).toEqual(['submitted'])
  516. const gated = "${{ github.event_name != 'pull_request_review' || github.event.review.state == 'changes_requested' }}"
  517. const steps = lifecycleJob.steps.filter(isRecord)
  518. const tokenStep = steps.find(s => s.name === 'Create project token')
  519. const handleStep = steps.find(s => s.name === 'Handle repository event')
  520. expect(tokenStep).toMatchObject({ if: gated })
  521. expect(handleStep).toMatchObject({ if: gated })
  522. // issue-policy owns PR validation; it is read-only and a real gate.
  523. const policyPullRequest = workflowEvent(policy, 'pull_request')
  524. expect(policyPullRequest.types).toContain('ready_for_review')
  525. })
  526. })
  527. describe('npm release workflows', () => {
  528. it('keeps publication dispatch-only and pack in the PR workflow', () => {
  529. // pack stays in the PR/master release workflows so a PR proves the set packs.
  530. for (const file of ['release.yml', 'release-vendor.yml']) {
  531. const workflow = loadWorkflow(`.github/workflows/${file}`)
  532. if (!isRecord(workflow.jobs)) throw new TypeError(`${file} must define jobs`)
  533. expect(Object.keys(workflow.jobs).sort()).toEqual(['pack'])
  534. }
  535. // publication is workflow_dispatch-only (never a PR check) and keeps the
  536. // npm-publish environment plus the shared dist-tag group.
  537. for (const file of ['release-publish.yml', 'release-vendor-publish.yml']) {
  538. const workflow = loadWorkflow(`.github/workflows/${file}`)
  539. if (!isRecord(workflow.on) || !isRecord(workflow.jobs)) throw new TypeError(`${file} must define on and jobs`)
  540. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  541. const publish = workflow.jobs.publish
  542. if (!isRecord(publish)) throw new TypeError(`${file} must define a publish job`)
  543. expect(publish.environment).toBe('npm-publish')
  544. expect(publish.concurrency).toMatchObject({ group: 'Release-publish' })
  545. }
  546. })
  547. })
  548. describe('Documentation site publication', () => {
  549. it('keeps Pages deployment dispatch-only from a dsh-v* tag', () => {
  550. const workflow = loadWorkflow('.github/workflows/docs-pages.yml')
  551. const build = workflowJob(workflow, 'build')
  552. const deploy = workflowJob(workflow, 'deploy')
  553. if (!isRecord(workflow.on) || !isRecord(workflow.env) || !Array.isArray(build.steps)) {
  554. throw new TypeError('Documentation deployment must define on, env, and build steps')
  555. }
  556. // The site presents a released snapshot: a merge must never publish it, and
  557. // publication must never appear as a PR check.
  558. expect(Object.keys(workflow.on)).toEqual(['workflow_dispatch'])
  559. // RELEASE_PUBLISH makes release:verify reject every ref that is not a dsh-v*
  560. // tag naming this tree's version, so the site and the npm sequence share one
  561. // definition of a released version.
  562. const steps = build.steps.filter(isRecord)
  563. const verify = steps.find(step => step.name === 'Verify release version')
  564. const checkout = steps.find(
  565. step => typeof step.uses === 'string' && step.uses.startsWith('actions/checkout@'),
  566. )
  567. expect(verify).toMatchObject({
  568. env: { RELEASE_PUBLISH: 'true' },
  569. run: 'pnpm run release:verify --family dsh',
  570. })
  571. // Complete history: the release scripts read tags.
  572. expect(checkout).toMatchObject({ with: { 'fetch-depth': 0 } })
  573. // Projected source links stay on the public repository's master. That
  574. // repository advances only to each release commit, so its master never
  575. // carries unreleased work, while it retains only the most recent tags:
  576. // following the dispatched tag would leave every source link on a deploy
  577. // from an older tag unresolvable.
  578. expect(workflow.env.DOCS_REPOSITORY_REF).toBe('master')
  579. // The environment owns the deployment tag policy and the required reviewers.
  580. expect(deploy.environment).toMatchObject({ name: 'github-pages' })
  581. })
  582. })
  583. describe('Git hooks', () => {
  584. it('leaves frozen Agent Note sidecars to the archive verifier', () => {
  585. const lefthook = loadWorkflow('lefthook.yml')
  586. for (const hookName of ['pre-commit', 'pre-merge-commit']) {
  587. const hook = lefthook[hookName]
  588. if (!isRecord(hook) || !Array.isArray(hook.jobs)) {
  589. throw new TypeError(`lefthook must define ${hookName} jobs`)
  590. }
  591. const pairing: unknown = hook.jobs.find(
  592. (job: unknown) => isRecord(job) && job.name === 'translation pairing (staged records)',
  593. )
  594. expect(pairing).toMatchObject({ exclude: ['.agents/notes/archived/**'] })
  595. }
  596. })
  597. })
  598. function loadWorkflow(path: string): Record<string, unknown> {
  599. const workflow: unknown = yaml.load(readFileSync(resolve(root, path), 'utf8'))
  600. if (!isRecord(workflow)) throw new TypeError(`${path} must define a workflow`)
  601. return workflow
  602. }
  603. function workflowEvent(workflow: Record<string, unknown>, event: string): Record<string, unknown> {
  604. if (!isRecord(workflow.on) || !isRecord(workflow.on[event])) {
  605. throw new TypeError(`workflow must define the ${event} event`)
  606. }
  607. return workflow.on[event]
  608. }
  609. function workflowJob(workflow: Record<string, unknown>, job: string): Record<string, unknown> {
  610. if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs[job])) {
  611. throw new TypeError(`workflow must define the ${job} job`)
  612. }
  613. return workflow.jobs[job]
  614. }
  615. function isRecord(value: unknown): value is Record<string, unknown> {
  616. return typeof value === 'object' && value !== null && !Array.isArray(value)
  617. }